Hi, I am working on a J2EE Project with JSP, EJB and Servlets. I have a requirement which requires me to throw a warning message when a user changes some values in a screen and tries to go out of the screen without saving it. There is a catch here. I have implemented the left menu bar in a separate JSP and have included it in every other screens. So if the user modifies any of the screen values and then clicks the left menu bar, how will I be able to track the changes made in the screen values? If any of you have any suggestions, please help me out. Thank you in advance.
Create a 'has_changed' javascript variable in the parent frame. In every form field, set the 'has_changed' var to true from the onchange event.
Have your nav bar buttons check 'has_changed' and invoke a confirm dialog from the onclick event of the menu buttons if it's true. [ July 28, 2005: Message edited by: Ben Souther ]
You could also use the onBeforeUnload handler of the page body (might be named slightly differently), which will be invoked before a page gets replaced. From inside it you can prevent a new page from being loaded if necessary. But you'd still need to keep track of altered fields, as suggested above.