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 2 of 2
  1. #1
    New Coder
    Join Date
    Jan 2004
    Location
    Kentucky
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    When to run data validation

    I'm writing a validation function to check a form. I have it set to trigger with the submit button onClick. Problem is that is DOES trigger and run, but then the form still proceeds to process. Where should I put the command to run the function and what syntax do I use.

    Thanks in advance.


    This is related to my post at:

    http://www.codingforums.com/showthre...2&goto=newpost
    -- Always thankful for kind and patient teachers willing to help a beginner.

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Do not use onclick on the submit button. Leave it as it is (if a submit) and let the function to be fired from FORM tag by the event handler OnSubmit. Give a return condition here and specify the return true/false in the validate function.

    <script>
    function validate(){
    if (true condition here){
    return true;
    }
    else {
    return false;
    }
    }
    <script>
    .
    .
    .
    <body>
    <form onsubmit = "return validate()">

    .
    .
    .
    <input type="submit">
    </form>
    </body>

    Or use the false condition to return false, whatever....
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

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