andy
Posts: 183
|
| Posted: 11/07/2007, 2:08 AM |
|
I have found a solution.
It is entirely javascript and does not use the CCS BeforeUnload event.
Instead it is based on the javascript onbeforeunload event.
Add the following code to the head section of your page:
<script language="JavaScript" type="text/javascript">
var unsaved = false;
var unsubmitted = true;
window.onbeforeunload = function(){if((unsaved==true) && (unsubmitted==true)){return "You have unsaved data. Are you sure you wish to leave this page.";}};
</script>
For each form field add unsaved = true; against the onchange event on the Format tab of the field's Properties box.
Each form field will then have the following code:
<input onchange="unsaved = true;" value="{Memorandum}" name="{Memorandum_Name}">
Then for each form button (Save, Cancel, Delete...) add unsubmitted=false; against the onclick event on the Format tab of the field's Properties box.
Each form button will then have the following code:
<!-- BEGIN Button Button_Insert --><input class="Button" onclick="unsubmitted=false;" type="submit" value="Add" name="{Button_Name}"><!-- END Button Button_Insert -->
The javascript code displays a message box asking the user whether they wish to leave the page before saving only if
* a field value has been changed (the user has started to add to the form)
* the form isn't being submitted or cancelled by the user by clicking on the buttons
The only fly in the ointment, which I haven't started to think about yet, is if you set a field to display a default value. If the user lands on the page, makes no changes and attempts to navigate away, he will be prompted becuase javascript thinks the default value has changed from null to the default value. I'm sure there's an easy js solution...
_________________
Andy
RAD tools for rich UI controls:
http://www.koolphptools.com |