I have multiple Numeric textbox as shown below in the snippet, all are currency format textbox's. How can I sum the values of textboxes in Class Name Charges
and display the total sub-total-Of-Charges
textbox and subtract if any value in textbox's with class=sub
from sub-total-Of-Charges
textbox value.
I have used the following jQuery Code which is working but two problems.
Doesn't Keep the currency format
the value of
net-invoiced-amount
is updated only when I update textbox value in textbox class .sub same thing.sub-total-Of-Charges
value is updated on.Charges
are updated but I need to re-calculate or update the valuenet-invoiced-amount
or.sub-total-Of-Charges
whenever .sub or .charges textbox's values are changed.$(document).ready(function () { $(document).on("change", ".charges", function () { var calculated_total_sum = 0; $(".charges").each(function () { var get_textbox_value = $(this).val(); if ($.isNumeric(get_textbox_value)) { calculated_total_sum += parseFloat(get_textbox_value); } }); $(".sub-total-Of-Charges").val(calculated_total_sum); });
$(document).on("change", ".sub", function () {
var netInvoicedAmount = $(".sub-total-Of-Charges").val(); $(".sub").each(function () { var get_textbox_value = $(this).val(); if ($.isNumeric(get_textbox_value)) { netInvoicedAmount -= parseFloat(get_textbox_value); } }); $(".net-invoiced-amount").val(netInvoicedAmount).trigger("change"); });
});