jquery - Sum multiple inputbox values -


i have bunch of inputboxes class "selectme quantity" , sum amount of together.

for example:

<input class="selectme quantity" value="4"> <input class="selectme quantity" value="1"> <input class="selectme quantity" value="5"> 

how can run through these inputs , display total value (it 10)?

i'd suggest:

function summate (selector) {     var sum = 0;     $(selector).each(function(){         sum += parsefloat(this.value) || 0;     });     return sum; }   summate('.selectme.quantity'); 

js fiddle demo.

or, if you're working browser supports array.reduce():

var sum = $('.selectme.quantity').map(function(){     return this.value && parsefloat(this.value); }).get().reduce(function(a,b){     return parsefloat(a) + parsefloat(b); });  console.log(sum); 

js fiddle demo.

references:


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -