onsubmit()

Discussion in 'JavaScript' started by askscript, Nov 17, 2008.

  1. #1
    Hi,

    i saw a code that was written like this:
    Does this mean that the form is not submitted since it is "return false"?
     
    askscript, Nov 17, 2008 IP
  2. xlcho

    xlcho Guest

    Messages:
    532
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Yep, it means just that. It's commonly used when you want to verify data before submitting the form. I.e. you have a form with a function that executes onsubmit:
    <form onsubmit='return verifyFormData()'>
    Code (markup):
    And the verification function should be something like this:
    function verifyFormData()
    {
       if( ... ) //here are the data verifications, i.e. numeric values, alphanumeric values, etc.
       {
          //if they all match your requirements - submit the form
          return true;
       }
       else  //something is not ok - warn the user to correct the wrong values and don't submit the form
       {
          alert('Data verification failed');
          return false;
       }
    }
    Code (markup):
     
    xlcho, Nov 18, 2008 IP