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 to the CF scene
    Join Date
    Aug 2002
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Multiple "onSubmit" form events

    On my website, I have a registration form, and I need scripts to validate that all the fields are fill in and the email address and passwords are valid. Therefore I have multiple "onSubmit" events, but then the form doesn't function properly. How can I fix this problem? PLEASE HELP!!

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Round Rock, Texas
    Posts
    443
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Conventional wisdoms says use one ONSUBMIT (i don't even know if multiple ONSUBMIT is possible for a single form) that kicks off a javascript function on the client side that validates all your fields at once.

    Alternatively you could validate fields on an individual basis by using the ONBLUR event for that fields.

    In our web development we validate date formats (or any other field with specific formatting requirements) using ONBLUR then the ONSUBMIT kicksoff a function that checks if all the required fields are filled in.

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Posts
    1,404
    Thanks
    2
    Thanked 32 Times in 32 Posts
    A word or two of explanation:

    onsubmit isn't an event, it's an event handler (property) belonging to a Form object. You can assign it to handle as many submit events as you like; you're assigning a variable so, every time you re-assign it, the old value (event handler) is simply overwritten. Solution:

    <form..........onsubmit="return validator1() && validator2()">

    ...or just call a 'master' function like this:

    <form..........onsubmit="return validator()">

    ...and:

    function validator() {
    if (!validator1()) return false;
    if (!validator2()) return false;
    return true;
    }

    Hope that helps.


  •  

    Posting Permissions

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