How to calculate the total value of input boxes using jquery
I have a list of input boxes, now 开发者_C百科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?
Would something like this work?
var sum = 0;
$('input[name^="pre"]').each(function(){
sum += parseFloat(this.value);
});
^=
is the Attribute Starts With Selector.
I would do it like this
var sum = 0;
find("input[name*='pre']").each(function(index) {
sum = sum + this.val();
})
精彩评论