I'm using ASP.NET 2.0 with a Master Page, and I was wondering if anyone knew of a way to detect when the fields within a certain <div>
or fieldset
have been changed (e.g., marked 'IsDirty
')?
var somethingChanged = false; $(document). ready(function() { $('input'). change(function() { somethingChanged = true; }); }); But, keep in mind that if the user changes something, then changes back to the original values, it will still be flagged as changed.
The change() is an inbuilt method in jQuery that is used to detect the change in value of input fields. This method works only on the “<input>, <textarea> and <select>” elements.
Answer: Use the input Event You can bind the input event to an input text box using on() method to detect any change in it.
Approach 2: There are few other events that can be used to detect the change in content of textbox. Use any or all of them onchange event, onpropertychange event, onkeyup event, onpaste event and oninput event in the input element and call a function to see the effect.
You could bind the Change event for all inputs and flag a variable as true. Like this.
var somethingChanged = false; $(document).ready(function() { $('input').change(function() { somethingChanged = true; }); });
But, keep in mind that if the user changes something, then changes back to the original values, it will still be flagged as changed.
UPDATE: For a specific div or fieldset. Just use the id for the given fieldset or div. Example:
var somethingChanged = false; $(document).ready(function() { $('#myDiv input').change(function() { somethingChanged = true; }); });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With