Search code examples
javascriptjqueryparsley

Change event to check change on any form element


I have a from with disabled button, which gets enabled when the form is valid. With the function below I'm checking for changes and it works if the form consists only of inputs. How can I check for change on other elements like select or checkbox?

$("#create-rule-form").parsley();
$('input').on('keyup', function() {
  $("#create-rule-form").parsley().validate();
  if ($("#create-rule-form").parsley().isValid()) {
    $('#create-rule-btn').prop('disabled', false);
  } else {
    $('#create-rule-btn').prop('disabled', 'disabled');
  }
});


Solution

  • Use jQuery's :input selector, it matches all tags that are used for form input.

    $(":input").on('edit change').function() {
      // code here
    });