HTML and CSS Reference
In-Depth Information
The following step enters the statements to convert the text field to uppercase characters and test for blank or
null values in the findItem() user-defined function.
1
Click line 7.
in Table 12-36 on the
previous page and then
press the e n t e r key after
line 14 to enter the
findItem() user-defined
function (Figure 12-40).
Enter the code shown
beginning of findItem()
user-defined function
and code to validate data
entered in text field box
press e n t e r
key once
Figure 12-40
Searching the Recordset Values and Outputting Results
After testing that the SearchText text field input value is not blank or null, the
findItem() user-defined function sequentially searches through the data in the linked XML
document, chapter12-1products_solution.xml, to find a match for the text box input value.
The search uses the data source object, dsoInventory, and Internet Explorer's built-in
methods to move through the records in the XML document. If a match is found, the
function creates a results message that incorporates specific XML elements in the HTML
string. Table 12-37 shows the JavaScript code that sequentially searches the XML document
and creates the results message to be displayed in the output area.
Table 12-37 Code for Searching the Recordset Values and Building the Output String
Line
Code
15
dsoInventory.recordset.moveFirst()
16
var outputResult=””
17
while (!dsoInventory.recordset.EOF) {
18
itemString=dsoInventory.recordset(“item-description”).value.
toUpperCase()
19
if (itemString.indexOf(SearchString)>=0)
20
outputResult+=dsoInventory.recordset(“item-description”)
21
+" Item # <span style='font-style:italic; font-weight:bold;'>" +
dsoInventory.recordset("item-id")
+ ". We have </span> "
22
+ dsoInventory.recordset(“item-boh”)
23
+ " in stock at a cost of <span style='font-weight:bold;
color:#cc0000;'>$"
24
+ dsoInventory.recordset("item-cost") + ".</span><p></p>"
25
dsoInventory.recordset.moveNext();
26
}
27
Recall that a recordset is a collection of data records. The built-in moveFirst()
method on line 15 positions an internal pointer to the first record in the recordset of the
data source object, dsoInventory. Line 16 initializes an output variable, outputResult, to
 
Search WWH ::




Custom Search