HTML and CSS Reference
EXAMPLE 13.26 ( CONTINUED )
alert ("Good Morning");
alert("Let's have lunch.");
<input type="button" id="button1" value="Morning" />
<input type="button" id="button2" value="Noon" />
<input type="button" id="button3" value="Night" />
Some global variables are defined to be used later in the script.
The onload event property of the window object mimics the behavior of the HTML
onLoad event handler of the body element. The function defined will be called
when a document or frameset is completely loaded into its window or frame.
The document.getElementById() method takes the id of each of the HTML buttons
the click event when the user clicks one of the buttons. The function called morn-
ing is assigned to this property and will be called when “button1” is clicked. Note
that this is a reference to the function and there are no quotes or parentheses. The
actual function it references is on line 5.
This is the actual function that will be called when the user clicks the “Morning”
Three HTML buttons are defined in the document. Each is given a unique id to be
method. See Figures 13.44 and 13.45.