I'd like to count the sum of all the numeric values of a lot of input fields inside a form, every time one of the values changes. I think this code is quite closer, but when I change twice the same input it is wrong.
tot = 0;
$('form#form-id :input').change(function(){
$("form#form-id :input").each(function(){
tot += Number($(this).val());
});
console.log(tot);
});
This also seems to works well on jsFiddle https://jsfiddle.net/yq9zenaz/ but I get NaN on production.
if(!isNaN($(this).val())) { //Your code }