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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

URGENT-How do I call multiple JS Validation Functions in a HTML Form?

Status
Not open for further replies.

Michela

Programmer
Mar 1, 2002
2
IE
Hi,
I'm really new to Javascript. I'm trying to use a date validation check function and a password validation check function at the same time.

WHen I use the usual OnSubmit= "return FunctionName();"
each function works fine individually.

However when I try to use them together, it doesn't work. The approaches I've used are as follows:
1. OnSubmit= "return FunctionName(); return AnotherFunction();"

2. OnSubmit= "return Do All(); where DoALL() calls both of the above two function like:
Function Do All(){

return FunctionName();
return AnotherFunction();
}

3. OnSubmit = "return FunctionName();" where FunctionName() calls AnotherFunction () at its end.

There is probably a very obvious solution to this, which i would appreciate if someone could point out!!,
Thanks.

 
Hi,
As discussed here before, the right way of doing this is #2. The #3 may be also good. The main idea is that you call only one function on form submit. What does this function contain in it's body - it's another story.
If you say that you tried these ways but it doesn't work it means that there's a problem in your code. Probably it's the way you handle return values from validation functions, or something else. It's impossible to give an answer without seeing what you tried to do.
good luck
 
You can't return two values. It's like trying to say two things out of your mouth at the same time!

However, if someone asks you if BOTH questions are true, then you can say either YES or NO, depending on whether both are true.

Bleh...

onsubmit="return functionOne() && functionTwo()"

The && operator returns true only of both functionOne and functionTwo return true. Otherwise, it will return false and the form will not submit.


If you want to make sure that both functions are carried out, then you can do this:

onsubmit="a=functionOne();b=functionTwo(); return a && b"

That's because &&, if functionOne() returns false, will not carry out functionTwo(). If you want to make sure that both are called, then you must call them individually.
bluebrain.gif
blueuniment.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top