View Full Version : need two [onsubmit="return] for two different scripts
chucktcl
08-10-2002, 08:26 AM
Hi,
How can I use or can I use two [onsubmit="return] for two different scripts on one form line. What I mean exactly is
if I need the two following onsubmit="return event handlers,
how do I incorporate both of them to be used in the same
form?
<FORM NAME=addform ACTION="/cgi-sys/formmail.pl" METHOD="POST" onsubmit="return submitForms()">
//and
<form onSubmit="return emailCheck(this.email.value);">
This is assuming I am able to merge the two javascripts together correctly so they will both produce the desired results.
Or would it be better to keep the two scripts separate
and have two form lines run the scripts separately? If the
latter is true how is this done?
Thanks,
Chuck
kansel
08-10-2002, 11:55 AM
If both scripts are supposed to return a true value on successful validation (as one would hope) you may do something like this
onsubmit="return (submitForms() && emailCheck(this.email.value))?true:false"
this is functionally equivalent to the following pseudocode if statement
if submitForms() == true AND emailCheck(this.email.value) == true
then return true (form is submitted)
else return false (form is not submitted)
adios
08-10-2002, 08:07 PM
<form.....onsubmit="return submitForms() && emailCheck(this.email.value)">
chucktcl
08-10-2002, 09:43 PM
Hi and thanks for responding to my post. Would you happen to know why the second part of the onsubmit="return submitForms() && emailCheck(this.email.value);">.... [&& emailCheck(this.email.value)] isn't being interperted (processed) by the script? It is seeing one of the code lines as 'undefined', however when the script is all by itself and onsubmit="return emailCheck(this.email.value);" is used it works just fine.
Thanks again,
Chuck
adios
08-10-2002, 09:59 PM
Post:
The exact code you used.
The exact error message.
thanks
chucktcl
08-10-2002, 10:07 PM
Yes, but why? How can I make the two scripts works together?
Thanks,
chuck
adios
08-10-2002, 10:23 PM
Yes, but why?
http://www.codingforums.com/showthread.php?threadid=3758
chuck -
Looked at your attachment, and don't follow why you're calling the e-mail validator separately - when it's already being called:
function submitForms() {if ( isFname() && isLname() && isEmail() && emailCheck()
Once is enough...
Took a closer look - how did you paste this together? It appears to come from several scripts, not designed as a unit (with the form itself). I think you've got more problems than just the onsubmit handler.
chucktcl
08-10-2002, 10:49 PM
Yes, I did splice three scripts together but it seems to me that this should work. I called both handlers for both functions so they would both operate. However, only the submitForms() produces an output and when the script tries to run the function emailCheck(emailStr) it gets this 'undefined' is null or not an object. But like I said the exact same event handlers work just fine when the scripts are run separately, so why won't these two handlers work when they are put together like this:
<.....onsubmit="return submitForms() && emailCheck(this.email.value)"> That should work because it's calling the two functions correctly and if the criteria is met then I don't see why it wouldn't return true, instead of getting this 'undefined' error, right?
thanks,
chuck
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.