Handy jQuery snippet of the day (sum input fields)

June 19th, 2013 by admin Leave a reply »

Here is a little handy piece of code I wrote that greatly simplifies summing values across a bunch of text inputs on your page, all you have to do is stick a class on the inputs you want to sum, in my case the class was ‘budget’ and voila, you will have the sum without having to do a bunch of this + that.

var budgetTotal = 0;
$('.budget').each(function (e, s) {
     budgetTotal += parseFloat($(s).val());
});

Advertisement

Leave a Reply