New Response

« Return to the main article

You are replying to:

  1. Hello:

    I have used the onbeforeunload event and it worked. I wanted to step it up a notch to include only if any fields on a form where filled out to fire the onbeforeunload event. I copied the code outlined above but it doesn't fire....below is my code. =============================== <html>

    <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <meta name="GENERATOR" content="Microsoft FrontPage 6.0"> <meta name="ProgId" content="FrontPage.Editor.Document"> <title>Add New Application Step 1</title> <base target="_self"> <script> <!--

    var isDocBeingSubmitted = false;

    function isFormChanged() { var rtnVal = false; var frm = document.forms[0]; var ele = frm.elements;

    for ( i=0; i < ele.length; i++ ) { if ( ele[i].type.length > 0 ) { if ( isElementChanged( ele, i ) ) { rtnVal = true; break; } } } return rtnVal; }

    function isElementChanged( ele, i ) { var isEleChanged = false; switch ( ele[i].type ) { case "text" : if ( ele[i].value != ele[i].defaultValue ) return true; break; case "textarea" : if ( ele[i].value != ele[i].defaultValue ) return true; break;

    case "radio" : if ( ele[i].checked != ele[i].defaultChecked ) return true; break;

    case "select-one" : for ( var x =0 ; x <ele[i].length; x++ ) { if ( ele[i].options[ x ].selected != ele[i].options[ x ].defaultSelected ) return true; } break;

    case "select-multiple" : for ( var x =0 ; x <ele[i].length; x++ ) { if ( ele[i].options[ x ].selected != ele[i].options[ x ].defaultSelected ) return true; } break;

    case "checkbox" : if ( ele[i].checked != ele[i].defaultChecked ) return true; default: return false; break; } }

    function navigateAway() { msg = "----------------------------------------------------------\n"; msg += "Your form has not been saved.\n"; msg += "All changes you have made will be lost\n"; msg += "----------------------------------------------------------"; if (isFormChanged()){ //inbuilt get-out: hold control key to bypass message; if (isDocBeingSubmitted == false && event.ctrlKey == false) event.returnValue = msg; } }

    // --> </script> <script language="JavaScript" type="text/javascript"> function checkCR(evt) { var evt = (evt) ? evt : ((event) ? event : null); var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null); if ((evt.keyCode == 13) && (node.type=="text")) {return false;} } document.onkeypress = checkCR; </script>


    <body onbeforeunload="navigateAway()" bgcolor="#CCCCCC">

    <img border="0" src="images/AppAdd1.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <hr> <p><b><font color=#003366 face="Arial" size="4">APPLICATION STEP 1:&nbsp; </font> <font color="#0000FF" face="Arial" size="3">Applicant Information&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp; </font> <font color="#0000FF" face="Arial" size="4">&nbsp;</font></b><span style="vertical-align: text-bottom"><font color="#FF0000" face="Cooper Black" size="4">*</font></span><font color="#FF0000" face="Arial" size="1">Denotes a required field</font></p><form method="POST" action="AppAddStep2.asp" target="_self" onclick="onbeforeunload=null;return true;" onsubmit="return FrontPage_Form1_Validator(this)" name="FrontPage_Form1" style="position: absolute; border-style: outset; border-width: 3"> <b><font face="Arial" color="#FFFF00" size="1"> <span style="background-color: #FF0000">Remember never hit your browser BACK or REFRESH buttons UNLESS OTHERWISE STATED or you will loose your changes!</span></font><table border="0" cellspacing="1"> <tr> <td>&nbsp;</td> <td> <p></p> <p></p> <p></td> <td></td> <td></td> <td></td> </tr> <tr> <td height="18"><font face="Arial" size="2"><b>Prefix:</b></font></td> <td height="18"><font face="Arial" size="2"><b>First Name:</b></font></td> <td height="18"><font face="Arial" size="2"><b>Middle Name:</b></font></td> <td height="18"><font face="Arial" size="2"><b>Last Name:</b></font></td> <td height="18"><font face="Arial" size="2"><b>Suffix:</b></font></td> </tr> <tr> <td height="25"><font face="Arial" size="2"> <input type="text" name="Applicant_Contact_Name_Prefix" size="7" style="background-color: #FFFFCC; border: 1 solid #0000FF" tabindex="2"></font></td> <td height="25"><font face="Arial" size="2"> <input type="text" name="Applicant_Contact_First_Name" size="20" style="background-color: #FFFFCC; border: 1 solid #0000FF" tabindex="3"></font></td> <td height="25"><font face="Arial" size="2"> <input type="text" name="Applicant_Contact_Middle_Name" size="20" style="background-color: #FFFFCC; border: 1 solid #0000FF" tabindex="4"></font></td> <td height="25"><font face="Arial" size="2"> <input type="text" name="Applicant_Contact_Last_Name" size="20" style="background-color: #FFFFCC; border: 1 solid #0000FF" tabindex="4"></font></td> <td height="25"><font face="Arial" size="2"> <input type="text" name="Applicant_Contact_Name_Suffix" size="6" style="background-color: #FFFFCC; border: 1 solid #0000FF" tabindex="5"></font></td> </tr> </table> <table border="0" cellspacing="1"> <tr> <td><b><font size="2" face="Arial">Address Line 1:</font></b></td> <td><b><font size="2" face="Arial">Address Line 2:</font></b></td> </tr> <tr> <td><font face="Arial" size="2"> <input type="text" name="Street_Line1" size="42" style="background-color: #FFFFCC; border: 1 solid #0000FF" tabindex="6"></font></td> <td><font face="Arial" size="2"> <input type="text" name="Street_Line2" size="37" style="background-color: #FFFFCC; border: 1 solid #0000FF" tabindex="7"></font></td> </tr> </table> <table border="0" cellspacing="1"> <tr> <td><font face="Arial" size="2"><b>City:</b></font></td> <td><font face="Arial" size="2"><b>State:</b></font></td> <td><font face="Arial" size="2"><b>Zip:</b></font></td> <td></td> <td></td> </tr> <tr> <td><font face="Arial" size="2"> <input type="text" name="City" size="20" style="background-color: #FFFFCC; border: 1 solid #0000FF" tabindex="8"></font></td> <td> <!--webbot bot="Validation" s-display-name="State" b-value-required="TRUE" --><SELECT size="1" name="State" style="background-color: #FFFFCC; border: 1 solid #0000FF" tabindex="9"> <OPTION value="FL" selected> Florida<OPTION value="AK"> Alaska<OPTION value="AL"> Alabama<OPTION value="AZ"> Arizona<OPTION value="AR"> Arkansas<OPTION value="CA"> California<OPTION value="CO"> Colorado<OPTION value="CT"> Connecticut<OPTION value="DE"> Delaware<OPTION value="DC"> District of Columbia<OPTION value="FL"> Florida<OPTION value="GA"> Georgia<OPTION value="HI"> Hawaii<OPTION value="IA"> Iowa<OPTION value="ID"> Idaho<OPTION value="IL"> Illinois<OPTION value="IN"> Indiana<OPTION value="KS"> Kansas<OPTION value="KY"> Kentucky<OPTION value="LA"> Louisiana<OPTION value="ME"> Maine<OPTION value="MA"> Massachusetts<OPTION value="MD"> Maryland<OPTION value="MI"> Michigan<OPTION value="MN"> Minnesota<OPTION value="MS"> Mississippi<OPTION value="MO"> Missouri<OPTION value="MT"> Montana<OPTION value="NE"> Nebraska<OPTION value="NV"> Nevada<OPTION value="NH"> New Hampshire<OPTION value="NJ"> New Jersey<OPTION value="NM"> New Mexico<OPTION value="NY"> New York<OPTION value="NC"> North Carolina<OPTION value="ND"> North Dakota<OPTION value="OH"> Ohio<OPTION value="OK"> Oklahoma<OPTION value="OR"> Oregon<OPTION value="PA"> Pennsylvania<OPTION value="RI"> Rhode Island<OPTION value="SC"> South Carolina<OPTION value="SD"> South Dakota<OPTION value="TN"> Tennessee<OPTION value="TX"> Texas<OPTION value="UT"> Utah<OPTION value="VT"> Vermont<OPTION value="VA"> Virginia<OPTION value="WA"> Washington<OPTION value="WV"> West Virginia<OPTION value="WI"> Wisconsin<OPTION value="WY"> Wyoming</OPTION> </SELECT></td> <td><font face="Arial" size="2"> <input type="text" name="zip" size="20" style="background-color: #FFFFCC; border: 1 solid #0000FF" tabindex="10"></font></td> <td></td> <td></td> </tr> </table> <table border="0" cellspacing="1"> <tr> <td><font face="Arial" size="2"><b>Phone Number:</b></font></td> <td><font face="Arial" size="2"><b>Fax:</b></font></td> <td><font face="Arial" size="2"><b>Email:</b></font></td> </tr> <tr> <td><font face="Arial" size="2"> <input type="text" name="Applicant_Phone" size="20" style="background-color: #FFFFCC; border: 1 solid #0000FF" tabindex="11"></font></td> <td><font face="Arial" size="2"> <input type="text" name="Applicant_Fax" size="20" style="background-color: #FFFFCC; border: 1 solid #0000FF" tabindex="12"></font></td> <td><font face="Arial" size="2"> <input type="text" name="Applicant_Email" size="37" style="background-color: #FFFFCC; border: 1 solid #0000FF" tabindex="13"></font></td> </tr> </table> <input type="text" name="UID" size="20" value="<%=Session("UID")%>"> <table border="0" cellspacing="1" width="582"> <tr> <td width="574"> <p align="center"><input type="submit" value="Next >" name="B1" tabindex="14"></td> </tr> </table> </form>




Your Comments