I have an order form with about 30 text fields that contain numerical values. I\'d like to calculate the sum of all those values on blur.
I know how to select all te
A tad more generic copy/paste function for your project.
sumjq = function(selector) {
var sum = 0;
$(selector).each(function() {
sum += Number($(this).text());
});
return sum;
}
console.log(sumjq('.price'));
Use this function:
$(".price").each(function(){
total_price += parseInt($(this).val());
});
$('.price').blur(function () {
var sum = 0;
$('.price').each(function() {
if($(this).val()!="")
{
sum += parseFloat($(this).val());
}
});
alert(sum);
});
JS Fiddle