...

View Full Version : Multiple "onSubmit" form events



webdesign_123
08-24-2002, 05: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!! :)

RadarBob
08-24-2002, 06: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.

adios
08-24-2002, 11:35 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum