html - input array sum with jQuery -
hello have unknown quantity of inputs array name , class
<input type="hidden" name="hidden[1]" class="sum" value="31"> <input type="hidden" name="hidden[2]" class="sum" value="21"> <input type="hidden" name="hidden[3]" class="sum" value="321"> <input type="hidden" name="hidden[4]" class="sum" value="-31"> <input type="hidden" name="hidden[5]" class="sum" value="31.12"> <input type="hidden" name="hidden[6]" class="sum" value="0">
question how sum values of fields try use .each() , getelementbyclassname wont work
i tried using each, worked me. check if used parsefloat...
if have 'sum' class define elements must calculated, below code should work....
$(document).ready(function () { var total = 0; $('.sum').each(function (index, element) { total = total + parsefloat($(element).val()); }); alert(total); });
Comments
Post a Comment