Calculate and Recalculate

Asked

Viewed 51 times

0

I made this function to find the filled notes and when I do onload calculates it correctly. When I use the onkeypress="somaNotas" function that is in each input it calculates all wrong.

Does anyone have any idea what I’m doing wrong.

function somaNotas(){
jQuery('input[name="nota"]').each(function(media=0){
    if (jQuery(this).val()!==''){
        var idElem = jQuery(this).data('id');
        var nota = parseInt(jQuery('.media'+idElem).data('media'));
        var notaProva = parseInt(jQuery(this).val());

        nota += notaProva;
        media++;
    }
    mediaSoma = (nota/media).toFixed(1);
    jQuery('.media'+idElem).html(mediaSoma).data('media',nota);
    jQuery('.notas'+jQuery(this).data('id')).html(nota);
});
}
onload = somaNotas();
  • onload than?, window.onkeypress ?

  • 1

    use a snippet in this question. To test before publishing go to the Meta

  • is a form that is graded in php the amount of notes varies according to the level. So when you load the pagian I use onload to run the above function. And in the note fields have onpress with the same function to recalculate

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.