Why is my change handler never being fired?
I've got this jQuery:
- /* Whenever boxGrandTotal changes (which it does when any amount is entered in any of the "amount" input text elements), disable the save button if there is a discrepancy between the totals */
- $(document).on("change", '[id$=boxGrandTotal]', function () {
- //var savebutton = $("[id$=btnSave]");
- alert('entered the change handler for boxGrandTotal');
- var savebutton = document.getElementById('[id$=btnSave]');
- var payment = parseFloat(document.getElementById('[id$=boxPaymentAmount]').value).toFixed(2);
- var total = parseFloat(document.getElementById('[id$=boxGrandTotal]').value).toFixed(2);
- if (payment == null) payment = 0;
- if (total == null) total = 0;
- if (payment == total) {
- savebutton.attr("disabled", false);
- return true;
- } else {
- alert('Total and Payment Total do not match. Please enter the same amount for both values and try again!');
- savebutton.attr("disabled", true);
- return false;
- }
- });
This should fire any time boxGrandTotal is updated, right? boxGrandTotal is, indeed, being updated, but I never see "entered the change handler for boxGrandTotal"
And there *is* a TextBox / text input element whose ID ends with "boxGrandTotal"
So why is the 'change' handler not firing, when the value in boxGrandTotal *is* changing? It is changed thus:
- $(document).on("blur", '.amountbox', function (e) {
- var amount1 = $('[id$=boxAmount1]').val() != '' ? parseFloat($('[id$=boxAmount1]').val()) : 0;
- var amount2 = $('[id$=boxAmount2]').val() != '' ? parseFloat($('[id$=boxAmount2]').val()) : 0;
- var amount3 = $('[id$=boxAmount3]').val() != '' ? parseFloat($('[id$=boxAmount3]').val()) : 0;
- var amount4 = $('[id$=boxAmount4]').val() != '' ? parseFloat($('[id$=boxAmount4]').val()) : 0;
- var amount5 = $('[id$=boxAmount5]').val() != '' ? parseFloat($('[id$=boxAmount5]').val()) : 0;
- var grandtotal = amount1 + amount2 + amount3 + amount4 + amount5;
- $('[id$=boxGrandTotal]').val(parseFloat(grandtotal).toFixed(2));
- });