admin管理员组

文章数量:1287608

Is there a ready-made way (maybe in one of the frameworks) to detect whether a form has changed pared to its original values?

The onchange event won't do, because it fires regardless of actual change (I could for example tick a checkbox on, and off again, with two onchange events).

The last resort would be to store each element's original value in a hidden field, and go through each one. If there is a faster method, I'd be happy to hear about it!

Is there a ready-made way (maybe in one of the frameworks) to detect whether a form has changed pared to its original values?

The onchange event won't do, because it fires regardless of actual change (I could for example tick a checkbox on, and off again, with two onchange events).

The last resort would be to store each element's original value in a hidden field, and go through each one. If there is a faster method, I'd be happy to hear about it!

Share Improve this question edited Dec 29, 2011 at 14:54 Rob W 349k87 gold badges807 silver badges682 bronze badges asked Nov 24, 2009 at 3:01 PekkaPekka 450k148 gold badges985 silver badges1.1k bronze badges 2
  • 2 See stackoverflow./questions/598951/… – Crescent Fresh Commented Nov 24, 2009 at 3:03
  • Cheers, serializing was the new idea I was looking for. – Pekka Commented Nov 24, 2009 at 3:25
Add a ment  | 

2 Answers 2

Reset to default 11

I'm not aware of any DOM event that detects changes made to children/descendant elements' value attributes, but it should be enough to pare the serialized values before/after, $('form').serialize(). I apologize if you already knew about this method specifically, I'm assuming you're manually going through form elements and appending values to a string.

I'm hunting for the same answer - here's the best potential solution I've e across (but haven't tried it yet): http://www.codingforums./showthread.php?t=29410&highlight=form+dirty

本文标签: javascriptDetect actual form changeStack Overflow