babelfish
07-28-2010, 11:10 AM
hi all,
ok, i have been asked to alter our project management system (one i wrote) to alert users to the fact that they are closing windows with unsaved work in - some of them forget they have edited a page and just close the window.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
var docChanged = false;
function docChange(){
docChanged = true;
}
function checkForChanges() {
if(docChanged == true) {
return "All changes made to this page will be lost!";
}
}
window.onbeforeunload = checkForChanges;
</script>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<label>
<input type="text" name="one" id="one" onchange="docChange()" />
</label>
<label>
<input type="text" name="two" id="two" onchange="docChange()" />
</label>
<br />
<a href='http://www.google.com'>Google</a>
</form>
</body>
</html>
the above will prompt the user if they want to save if fields etc have been changed.
is there a way i can dynimcally add the onchange="docChange()" to all fields on a page? the system has hundreds of fields and doing a mass search and replace might be very dangerous lol. im pretty sure it can be done but wouldnt know where to start. ive never really had enough time to learn all the window.addEventListener stuff.
ok, i have been asked to alter our project management system (one i wrote) to alert users to the fact that they are closing windows with unsaved work in - some of them forget they have edited a page and just close the window.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
var docChanged = false;
function docChange(){
docChanged = true;
}
function checkForChanges() {
if(docChanged == true) {
return "All changes made to this page will be lost!";
}
}
window.onbeforeunload = checkForChanges;
</script>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<label>
<input type="text" name="one" id="one" onchange="docChange()" />
</label>
<label>
<input type="text" name="two" id="two" onchange="docChange()" />
</label>
<br />
<a href='http://www.google.com'>Google</a>
</form>
</body>
</html>
the above will prompt the user if they want to save if fields etc have been changed.
is there a way i can dynimcally add the onchange="docChange()" to all fields on a page? the system has hundreds of fields and doing a mass search and replace might be very dangerous lol. im pretty sure it can be done but wouldnt know where to start. ive never really had enough time to learn all the window.addEventListener stuff.