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-amountis updated only when I update textbox value in textbox class .sub same thing.sub-total-Of-Chargesvalue is updated on.Chargesare updated but I need to re-calculate or update the valuenet-invoiced-amountor.sub-total-Of-Chargeswhenever .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"); });});
You need to get reference of textbox where you need to set the updated value using
data("kendoNumericTextBox")and then set new value using.value("newwvalue")this will update new value according to the format which you have set earlier .Also , use
$(this).attr("aria-valuenow")to get the original value of textbox without any currency and change your selector to$(".k-formatted-value.charges")to get only input value from particular textbox .Currently , when you will inspect html generated it has 2 input box with same class that's the reason total sum is not working.Demo Code :