Ask the Expert

Prompt user save before clicking another link

I have navigator in the left frame and forms or views in the right frame. If a user is editing a document in the right frame and then they click the link in the left navigator without saving the document, they lose their data. How can I prompt the user to save the document before they can click on the other link, after they edited the document?
Here's a simple description for a solution that will work:
  1. Create a hidden, but editable, field that can be used as a flag. Default the field value to "NotSaved."

  2. Set the "Edit" action on the form to ensure that the flag is set to "NotSaved" so that it will also be set whenever a document is put in edit mode. Here is sample formula action code:
    FIELD Flag := "NotSaved";

  3. Set the "Submit" or "Save" action to modify the flag field to something else before submitting the form. Here is sample JavaScript to do the trick:
    document.forms[0].Flag.value = "Saved";

  4. Put some JavaScript code in the form's onUnload event to catch when the user navigates away from the form:
    if (document.forms[0].
    Flag.value == "NotSaved")
     if (confirm ("Your changes have not
     been saved. Do you want to go back to the 
      // go back to the form 

This is a simplistic solution, but you should be able to customize it to meet your needs.

Do you have comments on this Ask the Expert question and response? Let us know.

This was first published in January 2005

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: