January 2001
Beginner
312 pages
6h 4m
English
Now that you've had a chance to write your first function and have practiced how to use events to trigger functions, you're ready to delve a little deeper.
The best way to think of functions is as a group of statements that perform a particular job. This can be a simple job requiring no more than one statement (as we saw previously) or a more complex function requiring many statements. Either way, functions perform a particular job.
So, if you return to the interactive story example, you can tidy this up and make it more user friendly by putting all the script into a function and using the onClick event on a button to trigger it off (see Figure 8.3):
<html> <head> <title>A Simple Page</title> <script language="JavaScript"> ...
Read now
Unlock full access