Sunday 15 January 2012

javascript - Get subtotal of inputs and then add -



javascript - Get subtotal of inputs and then add -

i have fiddle adds total of inputs , changes inputs change. need take business relationship quantity of each item.

so current total $105 should should $235, taking business relationship qty of 3 items $65.

checking out fiddle show mean.

http://jsfiddle.net/4n7k012b/1/

$(document).ready(function () { var sum = 0; //iterate through each textboxes , add together values $("input[class='cmb_text_money']").each(function () { //add if value number if (!isnan(this.value) && this.value.length != 0) { sum += parsefloat(this.value); } }); $("#sum").html(sum.tofixed(2)); $(document).on('keyup',"input[class='cmb_text_money']", function () { var sum = 0; //iterate through each textboxes , add together values $("input[class='cmb_text_money']").each(function () { //add if value number if (!isnan(this.value) && this.value.length != 0) { sum += parsefloat(this.value); } }); $("#sum").html(sum.tofixed(2)); console.log(sum); }); });

here's 1 way that, traversing quantity , multiplying price, storing each sum in array summed @ end

$(document).on('keyup', 'input.cmb_text_money, input.cmb_text_small', function () { var sum = $.map($('input.cmb_text_money'), function(item) { homecoming $(item).closest('tr').prev('tr').find('input').val() * item.value; }).reduce(function(a, b) { homecoming + b; }, 0); $("#sum").html(sum.tofixed(2)); });

fiddle

javascript jquery

No comments:

Post a Comment