Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Mar 2003
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    disable onunload if user submits the form only.

    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.

    Thanks,
    Hasan

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,922
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    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()">

  • #3
    New Coder
    Join Date
    Mar 2003
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up Thank you

    It was that easy....

    Thanks a bunch,

    Hasan


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •