How do you alert the user that they have unsaved changes in a form?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Aetos
    New Member
    • Jan 2013
    • 1

    How do you alert the user that they have unsaved changes in a form?

    I have a php form with several text fields which retrieve the data from a selected record in my database. I would like that if the user edits the data in the fields in some way, and tries to leave the page by clicking a link, clicking the back button or refreshing the page, they would be prompted that they have made changes to form and that they must verify if they want to leave the page or not.

    Any help is much appreciated.
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Use the onbeforeunload event. See, for example, the following article: http://bytes.com/topic/javascript/in...vascript-event

    You may want to keep a "dirty" variable which is set to false initially and when any changes are made, trigger a function in the above event.

    Comment

    Working...