More information about the Underscore mailing list

[_] Check if user has changed anything on form since last save

Hamish Atkinson hamish.atkinson at
Thu Dec 17 10:44:54 GMT 2009

Hi all, I have a long form that the user fills in.
It would be a 'mare to fill in and then quit without saving, so I want to a
add a popup when user clicks the close button, but only if they have changed
anything since they last saved (or the autosave saved the form).

I thought of maintaining a js variable formChanged and adding an onChange
event to every field that sets this to true.
Then the Close button would have onClick event that pops up a confirm
dialogue if this variable is set. (Admittedly, if user made a change and
then reversed that change before trying to close the window this would
falsely state that the form is modified. The only way to avoid that would be
to keep a complete copy of the form as loaded and compare each field of the
form with that copy when the user clicks close. Not difficult with
prototype, but rather excessive)

Or more simply, have 2 form close buttons instead of one: "Save & Close" and
"Close, Discard Changes" (Much as Gmail has "Send","Save Now", "Discard" as
an option as I write this message)

Has anyone got any better/more elegant ideas (or can point me at form
frameworks (PHP and/or javascript) that do this)?

Hamish Atkinson
hamish.atkinson at