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:

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


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 live online training, plus books, videos, and digital content from nearly 200 publishers.