tags:

views:

50

answers:

2

On stackoverflow, and other websites, if you start making a change to form elements and then you try to navigate away from the page, you will get a confirmation message asking if you are sure you want to discard your changes.

This seems relatively easy to do by hand, but impractical to apply across an entire site. Is there any generic solution that can be plopped onto a page as a control (or even jQuery plugin) which will track IsDirty for all fields (without having to specify each field by hand)?

A: 

A possiblity would be to clone a selection of all your inputs when the page is loaded (and data into it as well).

You could then do a compare as desribed here: http://chris-barr.com/entry/comparing_jquery_objects/

Word of warning though, this may be costly, performance wise.

James Wiseman
A: 

You can use the window.onbeforeunload event. See also http://stackoverflow.com/questions/276660/how-can-i-override-the-onbeforeunload-dialog-and-replace-it-with-my-own

Maurice