Reputation: 36829
I have a list of input boxes, now I need to calculate the total of all values entered in input boxes with the following naming convention pre[0],pre[1],pre[2] etc.
Is this possible with Jquery and how?
Upvotes: 2
Views: 5652
Reputation: 47280
I would do it like this
var sum = 0;
find("input[name*='pre']").each(function(index) {
sum = sum + this.val();
})
Upvotes: 0
Reputation: 50095
Would something like this work?
var sum = 0;
$('input[name^="pre"]').each(function(){
sum += parseFloat(this.value);
});
^=
is the Attribute Starts With Selector.
Upvotes: 10