HTML and CSS Reference
In-Depth Information
To Enter the End Comment and End </script> Tags
Table 9-28 shows the code used to close the start <script> tag on line 6 and the start comment tag on line 7, as
entered in Figure 9-4 on page HTML 418.
Table 9-28 Closing the Script Section
Line
Code
//-->
44
</script>
45
Line 44 ends the comment, <!--Hide from old browsers, that was started on line 7. If the HTML comment
line is used and it is not closed properly, it will read the rest of the Web page document as part of the comment.
The end </script> tag on line 45 ends the JavaScript code section and prevents the HTML code that follows from
being interpreted as JavaScript code. The following step enters the end comment tag and the end </script> tag.
1
blank line 44.
If necessary, click
code shown in
Table 9-28 and do
not press the e n t e r
key after the last line
(Figure 9-13).
What happens if a
<script> section is
not closed properly?
If the HTML
comment line is used
and it is not closed properly,
the rest of the Web page document will be treated as a comment. When the user attempts to
view the Web page, nothing will appear after that comment line.
Enter the JavaScript
closing HTML comment line
and closing </script> tag
function to display
date Web page
last modified
insertion point; do
not press ENTER
key after closing
</script> tag
Figure 9-13
Why is the comment needed in <script> sections?
Some browsers or mobile Web devices do not interpret JavaScript code correctly, so the comment
hides the JavaScript code. If the comment line is not closed properly, the Web page may not
display from the point of the comment forward, thus giving the impression the Web page is
blank. If this occurs, always check to ensure the end comment tag was included.
Plan
Ahead
Using event handlers to call user-defined functions.
Event handlers must be placed with the object (such as a button, drop-down menu, or HTML
tag) that controls the event. In this chapter, the events are load and change, so you use the
event handlers onLoad and onChange to call the user-defined functions. In this chapter, you
will:
Place the onLoad event handler in the <body> tag.
Place the onChange event handler in the <select> tag that starts the drop-down menu.
 
Search WWH ::




Custom Search