Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling Two functions on onSubmit.

Status
Not open for further replies.

yash

Programmer
Apr 9, 2001
46
IN
Hi,
Can we call more than one functions on onSubmit event.
I want to call two differnt functions on onSubmit event.
it doesn't work. If i call one function it workks fine..
Any idea.. If it is possible to call more than one functions what is syntax..
I'm calling like
onSubmit= "return radiomust(rm); return namemust(nm);"

Regards..
Yash
 
try this
<form ... onsubmit=&quot;return (radiomust(rm) && namemust(nm))&quot;>

------
and if it doesn't work, try this :
<form ... onsubmit=&quot;return trick_function()&quot;>

and
function trick_function()
{
return (radiomust(rm) && namemust(nm))
}
--------
and if it still doesn't work, let me know
 
Hi iza,
Thanks for your response..
It works .. I convert my two function into one JS file
Thanks and Best Regards..
 
Does anyone know if you can call 3 functions? I have 3 and the first two are working.

Thanks in advance,
scripter73
Change Your Thinking, Change Your Life.
 
The same techniques can be used to call 3, or 4, or 5 functions. Adding them to the onSubmit gets cumbersome though, so I'd use the single onSubmit function that calls the other functions. It's more flexible.
Code:
function submitter() {
  if ( !radiomust() ) return false;
  if ( !namemust() ) return false;
  if ( !checkmust() ) return false;
  if ( !selectmust() ) return false;
  return true;
}
...
<form ... onSubmit=&quot;return submitter()&quot;>
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Thanks, Tracy,

However, I'm trying to say the following:

<form .....onsubmit=&quot;return functiona();return functionb(); return functionc;&quot;>

And if functiona returns a false, then I don't want the others to continue, etc. Everything works fine for functions a and b, but when I throw functionc in and start passing parameters to it, the code doesn't execute.

Thanks for your help. I hope I didn't confuse you. Please let me know if you'd like an actual sample. There's a trivial bit of Cold Fusion thrown into the parms.

scripter73

Change Your Thinking, Change Your Life.
 
scripter73: Then use iza's solution.
Code:
onsubmit=&quot;return functionOne() && functionTwo() && functionThree()&quot;

The && operator will continue with execution only if the earlier expressions are true.
bluebrain.gif
blueuniment.gif
 
The code I gave for the submitter function will do the same thing. If a function returns false then so will the submitter function, otherwise it will continue and call the next function. If they all return true, the submitter function will return true. You can use more than one return in the onSumbit itself. iza's solution works, but as this thread illustrates, it gets cumbersome when you start adding additional functions.
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top