Results 1 to 4 of 4

Thread: Don't sumbit form if JS returns false?

  1. #1

    Thread Starter
    Frenzied Member Jmacp's Avatar
    Join Date
    Jul 2003
    Location
    UK
    Posts
    1,959

    Don't sumbit form if JS returns false?

    On clicking submit i have to run a JS functio to see if all fields are filled in, well if there not i give a message box etc but the form still posts am using,


    HTML Code:
    <form method="POST" action="verify.php">
      <input type="submit" value="Register" name="B1" onclick="checkfields()">
    </form>
    
    <script language = "javascript">
    
    function checkfields(){
    
    }
    
    </script>
    I need it not to post if any of the fields are empty

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Don't sumbit form if JS returns false?

    Change it to
    HTML Code:
    onclick="return checkfields()"
    And in your checkfields() function return TRUE to NOT post the form, FALSE to post it.

  3. #3

    Thread Starter
    Frenzied Member Jmacp's Avatar
    Join Date
    Jul 2003
    Location
    UK
    Posts
    1,959

    Re: Don't sumbit form if JS returns false?

    spot on as usual!

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Don't sumbit form if JS returns false?

    No problems, don't forget to mark your thread as Resolved from the Thread Tools menu

Posting Permissions

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



Click Here to Expand Forum to Full Width