Functions Running Functions!

You've seen how events can be used to trigger functions, but what about one function triggering another? That's simple! Here is an example of a function that contains an alert box triggered by the onLoad event and that triggered another function itself:

<html>
<head>
<title>A Simple Page</title>
<script language="JavaScript">
<!-- Cloaking device on!
function firstMessage()
{
alert("Here is the first message!");
secondMessage();
}
function secondMessage()
{
alert("And here is the second!");
}
// Cloaking device off -->
</script>
</head>
<body onLoad="firstMessage()">

</body>
</html>

When you load this page into the browser, the onLoad event triggers the function firstMessage(), which displays the first alert box ...

Get JavaScript™ 1.5 by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.