HTML and CSS Reference
In-Depth Information
Lines 6 and 7 start the <script> section of the Web page file. Line 8 declares the
adMsg variable and assigns the message string, "** Did you know some used cars can have
100% loan value? Ask for details! **" to it. The spaces at the beginning and end of the
message string ensure that spaces appear at both ends of the message. Line 9 declares the
beginPos variable, used to indicate the beginning position of the text string, and initializes
it to zero. Line 10 declares the function scrollingMsg(). Line 11 assigns the message string
to the text field object, which is constructed using the form (msgForm), the text field object
(scrollingMsg) as an attribute of the msgForm form object, and the value property. The
value property is used to assign text to the contents of the text field. Figure 10-4 illustrates
the relationship between these objects and how the statement is derived.
form text field object
text field name
scrollingMsg is
property of msgForm
form name identified
by id attribute
text field object named
with name attribute
text field size attribute
Figure 10-4
The rest of the assignment statement in line 11 uses the substring() method and
concatenates the remainder of the adMsg variable to the beginning of the adMsg variable.
As you learned in Chapter 9, the substring() method needs two parameters (x,y), where
x is the starting point of the string and y is the location of the last character needed.
This statement tells the scrollingMsg() function to assign the next character in the string
message to the text field, to make the message appear as if it is scrolling.
To Create the scrollingMsg() User-Defined Function
The following step creates the scrollingMsg() user-defined function and defines its variables.
1
text message assigned
to adMsg variable
line below the
<title> tag.
Click line 6, the blank
declares
position
variable
JavaScript
code shown in
Table 10-2 on
the previous page to
enter the beginning
script tags and define
the variables used in
the scrolling message,
indenting as shown. Press the e n t e r key to position the
insertion point on line 12 (Figure 10-5).
How can the scrolling message be formatted?
When using an <input> text field, you can format the text using an inline style.
Enter the
declares
function
form text field object
assigns message to form text
field object value property
Figure 10-5
 
Search WWH ::




Custom Search