View Full Version : Multiple "onSubmit" form events

08-24-2002, 06:50 PM
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!! :)

08-24-2002, 07:23 PM
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.

08-25-2002, 12:35 AM
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()">


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

Hope that helps.