Use onLoad to Call More than One Function with Javascript
To call more than one function in onLoad with Javascript:
<body onLoad="alert('First Hello!');alert('Second Hello!!')">
-We enclose Javascript's built-in
event handler onLoad in the body tag.
-We call Javascript's built-in
alert method twice, separated by a semicolon.
-We enclose our text in single quotes because it's already inside double quotes.
We could also call a script with onLoad that calls two functions:
function coolAl() {
firstHey();
secondHey();
}
function firstHey() {
alert("First Hello!");
}
function secondHey() {
alert("Second Hello!");
}
<body onLoad="coolAl()">
-We
created a function and named it
coolAl.
---Inside coolAl, we called our two other functions.
-We
created the two other functions and named them firstHey and secondHey.
-We
called our function coolAl in the onLoad event handler.
Free Copy and Paste Javascript Code:
<script type="text/javascript">
<!--
function coolAl() {
firstHey();
secondHey();
}
function firstHey() {
alert("First Hello!");
}
function secondHey() {
alert("Second Hello!");
}
-->
</script>
<body onLoad="coolAl()">
My home page
Resources:
Use onLoad in Body Tag with Javascript
Opening an Alert Box in Javascript
Call your Function in Javascript
Create a Function in Javascript