prevent exit from page without saving

Results 1 to 2 of 2

Thread: prevent exit from page without saving

  1. #1 Guest

    Default prevent exit from page without saving

    Does anyone have any suggestions for me on this problem??<BR><BR>I have a form within an ASP page that, upon exit (by any link) I would like to:<BR>-check to determine if any changes have been made to the form;<BR>-if there have been changes, validate/check that the save button has been selected to save changes;<BR>-if changes haven&#039;t been saved, return false preventing the exit and display an alert to the user.<BR><BR>I was anticipating using javascript for this task. But I am uncertain how to handle a couple of items...<BR>-I know how to validate forms for blanks or allowable characters, but how do I test for any changes (there may already be text in field or it may be updated)?<BR>-Will a return false work when trying to exit from any link?<BR><BR>Any thing else that I should consider?<BR><BR>Any help or ideas would be greatly appreciated.<BR><BR>Joe<BR>

  2. #2
    Eddie Campbell Guest

    Default RE: prevent exit from page without saving

    The way I do it is to store a hidden field on the form called BooIsDirty. <BR><BR>In the onchange event for each field on the form, I call a function which sets the value of the hidden field to be true.<BR><BR>Then In the body tag of the document, I call another function in the onbeforeunload event. This function tests the value of BooIsDirty, and if it is true, I prompt give the user the choice to exit without saving, or to return to the document.<BR><BR>When the user clicks the save button, I clear the value out of BooIsDirty.<BR><BR>Hope this helps<BR><BR>Eddie

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts