In jQuery, is there a simple way to test if any of a form’s elements have changed?
Say I have a form and I have a button with the following click() event:
$('#mybutton').click(function() {
// Here is where is need to test
if(/* FORM has changed */) {
// Do something
}
});
How would I test if the form has changed since it was loaded?
You can do this:
This rigs a
changeevent handler to inputs in the form, if any of them change it uses.data()to set achangedvalue totrue, then we just check for that value on the click, this assumes that#mybuttonis inside the form (if not just replace$(this).closest('form')with$('#myForm')), but you could make it even more generic, like this:References: Updated
According to jQuery this is a filter to select all form controls.
http://api.jquery.com/input-selector/