jeudi 22 juin 2017

JQuery - Unable To Detect Checkbox Change Event

Im currently working on the following JQuery:

$('table input[type=checkbox][data-tag=entity-value]').on('change',
    function () {
        var associatedTextboxID = $(this).attr('id').replace('IsAssociated', 'Value');
        var associatedTextbox = $('table input[type=text][id=' + associatedTextboxID + ']');

        if ($(this).prop('checked') && associatedTextbox.val() === "") {
            $(this).prop('border', '1px solid #FF0000');
            $(this).after("<p id='error' class='key-error'>While associated, value is a required field.</p>");
            $('#btnSaveCustomProperty').prop('disabled', true);
            $('#btnSaveCustomPropertyAndContinue').prop('disabled', true);
        }
        else if (!$(this).prop('checked')) {
            $('#error').remove();
            $('#btnSaveCustomProperty').prop('disabled', false);
            $('#btnSaveCustomPropertyAndContinue').prop('disabled', false);
        }
    });

Im trying to execute the block when the user changes the checkbox value. Stepping through the code in the browser reveals that the code does not execute when the checkbox is checked (or not).

Is there a better way to handle the checkbox event?




Aucun commentaire:

Enregistrer un commentaire