HTML and CSS Reference
In-Depth Information
a null value. Line 17 starts a while processing loop. As you learned in Chapter 10, the
while loop relies on a conditional statement to terminate. In this function, the while loop
processes each record until the EOF property is true. EOF means end of file and signals
that all XML document records have been read.
Line 18 assigns the values of the <item-description> element to the itemString
variable of the current record. To determine if the value in the SearchString matches
any part of the search text, the if statement in line 19 uses the indexOf() method to look
for SearchString value in itemString. Recall from Chapter 10 that the indexOf() method
returns the relative location of the value found. If the returned value is greater than or
equal to 0, indicating a match was found, lines 20 through 25 construct an output value
concatenating the various elements and descriptive text together. This method is used to
allow this script to be changed easily and adapt to searching any text string.
The <p></p> tags at the end of line 25 ensure that each outputResult string will
appear on a separate line in the output area of the Web page. To read each of the records in
the recordset, line 26 uses the built-in moveNext() method to tell the function to read the
next record in the XML document. Line 27 closes the while loop.
To Enter Code to Search the Recordset Values and Build the Output String
The following step enters the code to search the chapter12-1products_solution XML file for items using all or
part of the description.
1
If necessary, click
line 15.
Enter the code shown
in Table 12-37 to
search the recordset
values and build the
output string. Press the
e n t e r key after line 27
(Figure 12-41).
moveFirst() method
goes to first record
in data island
Why isn't there a
bracket ({) after the if
statement on line 19?
Normally, in JavaScript
you cannot break
statements in the
middle of a line. The
expression at line 20
is one exception
because an
expression
statement can be
broken at places like
operands. Recall that
if an if statement has
only one statement after
the condition, no brace is needed to set a block of code. In this
case lines from 20 to 25 are treated as one JavaScript expression.
while loop cycles
through all data
elements
concatenation
of selected
datafields to
form output
results
moveNext() method
moves to next record
press e n t e r
key once
Figure 12-41
 
Search WWH ::




Custom Search