Search code examples
javascriptjqueryhtmlpostal-code

HTML Input field value set by AJAX and catch that event


I have field in my html, and some third-party service will set it's value.

How could I catch that event when the field value is changing?

<input data-val="true" data-val-length="City cannot be longer than 30 characters." data-val-length-max="30" data-val-required="City is required." id="Address_City" maxlength="30" name="Address.City" type="text" value="">

How could I catch the value change of this field, I've tried .change event also,

    $('#Address_City').on('change', function() {
      console.log("Changed");
});

Solution

  • I think I found some solution, I'm going to use a timer here, there will be some permanence issues.. but I couldn't find anything be

    $('#Address_Address').on('change keyup paste click', function () {
        $('.pcaautocomplete .pcaselected').click(function () {
            var refreshInterval = setInterval(function () {
                if ($('#State').val() != "") {
                    var statusVal = $('#State').val();
                    clearInterval(refreshInterval);
                }
            }, 100);
        });
    });