Calculate and Recalculate

0

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

Someone has an idea of 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();
    
asked by anonymous 23.02.2017 / 17:45

0 answers