How To Sum the Values of Form Fields

1 2 3 4 5 6 7 8 9 10 |
var sum = 0; // loop through each field jQuery(".sum").each(function() { //add only if the value is number if( ! isNaN(this.value) && this.value.length != 0 ) { sum += parseFloat(this.value); } }); //.toFixed() rounds the sum to 2 decimal places jQuery("#sum").html(sum.toFixed(2)); |
Leave Your Comment
All fields marked with "*" are required.