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

calling two javascripts in one shot

Status
Not open for further replies.

gchen

Programmer
Nov 14, 2002
174
US
how can i envoke two javascripts while submitting a form?

can i use onSubmit for two javascripts or onClick, or there is other way?

Thanks gurus!
 
you could call one Javascript function in the onClick, and that function could have calls to as many other functions as you might want.

Kevin Petursson
 
Just put both function names (assuming the "scripts" you are refering to are functions) and seperate them with a semicolon (;)
Code:
<script language=javascript>
function function1() {
   alert("This is function1");
}
function function2() {
   alert("This is function2");
}
</script>
<form onsubmit='function1();function2()'>
<input type=submit value='Submit Me'>
</form>

-kaht

Weaseling out of things is important to learn. It's what separates us from the animals... except the weasel. - Homer Simpson (no, I'm not Homer)
 
first of all, thanks for the quick response!

i did that, but the question is the first one is a form data checker, so i have several if statement there. only if all passed, it will return "true", else return "false".

so when i call it, i use "return checkdata();".

then if i put another function next to it when i call from onsubmit like this --

<form onsubmit="return function1(); function2()">

i never had a chance to have function2() executed, no matter the return of function1() is true or false.

:((


 
if you are returning the values of the functions, make sure they both return a value and try this:
Code:
<form onsubmit="return (function1() && function2())">

-kaht

Weaseling out of things is important to learn. It's what separates us from the animals... except the weasel. - Homer Simpson (no, I'm not Homer)
 
GREAT!!!!! it did the trick!

Thanks a lot!

:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top