1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| <script language="JavaScript">
var ids = new Array('nom','editor1','supp');
var values = new Array('', '', '');
function populateArrays()
{
// assign the default values to the items in the values array
for (var i = 0; i < ids.length; i++)
{
var elem = document.getElementById(ids[i]);
if (elem)
if (elem.type == 'checkbox' || elem.type == 'radio')
values[i] = elem.checked;
else
values[i] = elem.value;
}
}
var needToConfirm = true;
window.onbeforeunload = confirmExit;
function confirmExit()
{
if (needToConfirm)
{
// check to see if any changes to the data entry fields have been made
for (var i = 0; i < values.length; i++)
{
var elem = document.getElementById(ids[i]);
if (elem)
if ((elem.type == 'checkbox' || elem.type == 'radio')
&& values[i] != elem.checked)
return "You have attempted to leave this page. If you have made any changes to the fields without clicking the Save button, your changes will be lost. Are you sure you want to exit this page?";
else if (!(elem.type == 'checkbox' || elem.type == 'radio') &&
elem.value != values[i])
return "You have attempted to leave this page. If you have made any changes to the fields without clicking the Save button, your changes will be lost. Are you sure you want to exit this page?";
}
// no changes - return nothing
}
}
</script> |
Partager