Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting data changes in forms using jQuery

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')?

like image 213
AlteredConcept Avatar asked Apr 30 '09 14:04

AlteredConcept


People also ask

How to detect form changes in jQuery?

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.

How to detect value change in jQuery?

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.

How to detect change in a text input box in jQuery?

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.

How to detect change in input text javascript?

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.


1 Answers

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;     });  }); 
like image 64
Jose Basilio Avatar answered Sep 30 '22 20:09

Jose Basilio