Q

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:
    @Command([EditDocument]);
    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";
    document.forms[0].submit();
    

  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 
    form?"))
     {
      // 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
This Content Component encountered an error

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

0 comments

Oldest 

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:

-ADS BY GOOGLE

SearchWinIT

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchEnterpriseLinux

SearchVirtualDataCentre.co.UK

Close