HTML and CSS Reference
Table 9-5 shows the naming conventions for a function name with valid and invalid
examples. A function name must begin with a letter or an underscore; it may contain
numerals, but may not contain any spaces, punctuation (such as periods or commas), or
reserved words. Data, as variables, are passed to a function in order for the function to
process data and return a result.
Table 9-5 Valid Function Names
Valid Function Names
Invalid Function Names
Must start with a letter or
No periods allowed or other
No spaces allowed
No hyphens allowed
To display a message with the current date and the number of days until a specific future
date, you must:
Create the <script> section in the <head> section
. In this project, the <script> sections will
be placed in the <head> section.
• . Using variables allows you to work with the system date, which
changes daily, to calculate the number of days from today to the Midwest Bridal Expo.
Calculate the number of days until the Midwest Bridal Expo
• . To calculate the number
of days to the Wedding Expo, you write code to subtract the current date from the
Display a message string
• . Use the innerHTML property to place the message on the
Web page. The innerHTML property allows you to change the contents of the text that
appears between an opening and closing of an HTML tag.
Close the <script> section
• . All HTML tags must have a closing tag. If you fail to close
the <script> section, you will have undesired results.
Add the event handlers
• . The event handlers call the function to display a dynamic
message when the Web page loads.
Inserting <script> Tags in the <head> Section
section, developers follow the coding practice and place user-defined functions and vari-
tag has a start <script> tag and an end </script> tag.
The general form of the script tag is shown in Table 9-6 on the next page. The
<script> tag supports several attributes, including src, type, and defer. In the past, the start
example, the preferred style is to use the type attribute. If the type or language attribute is
tags, it must be closed (using the format -->).
Many Web developers
the start <script> tag
and the end </script>
tag immediately as the
Web page is modified
or constructed. The
important rule to
remember is that a
complete set of <script>
tags must be included,
both <script> and