View Full Version : disable onunload if user submits the form only.

04-07-2003, 06:24 AM
I wonder if any one has any idea as i am a little new to j cripts.
The page has a form and this page a onunload script that always run if the user exists this page.
I do not want the page to execute this onunload script if the user submits the form.
I have a function that runs once the user submits this form to verify the data and i am sure i can add a small function to disable the onunload if this script runs.


Philip M
04-07-2003, 08:00 AM
Here is what I use - you can adapt it to suit your requirement:-

var submitok = 0;

function submitForm(s) { // called when submit form button pressed
submitok = 1;
return true;

function exitform2() {
submitok = 1; // window left via a link to another url so no error message

function exitform() { // on window unload, but no error if form was submitted
if (submitok == 0) {
alert ("Has the acknowledgement screen 'Thank you for your order!'\nbeen displayed? If not, you have not clicked on the green\nSUBMIT FORM button and your Order Form has not been sent.");

<BODY onunload="exitform()">

Links from the page thus:-

<a href="anotherpage.html" onclick="exitform2()">

04-07-2003, 08:20 AM
It was that easy....

Thanks a bunch,