HTML and CSS Reference
In-Depth Information
To Enter Code to Complete the findItem() Function
The next step is to test if the outputResult string has any content. If not, then a message to tell the users no
results were found is assigned to the SearchResult.innerHTML object. Table 12-38 shows the code for building the
no result found message.
Table 12-38 Completing the findItem() Function
Line
Code
28
if (outputResult==””)
29
SearchResult.innerHTML=“&ltSorry, that description was not found, please modify and try
again.&gt”;
30
else
31
SearchResult.innerHTML=outputResult
32
}
Line 28 tests the outputResult variable. If the outputResult is blank because no match was found on line 18,
then line 29 assigns a message to the SearchResult.innerHTML property that no record was found. If a match is
found, the else portion of the if...else statement on line 31 displays the outputResult results message constructed on
lines 20 through 25 using the innerHTML property. Line 32 ends the user-defined function. The following step
completes the findItem() function.
1
line 28.
If necessary, click
Enter the code
results message
if no description
match found
shown in Table 12-38
to complete the
findItem() function and
then press the e n t e r
key twice at line 32
(Figure 12-42).
output result set to
<div> area defined at
Figure 12-39 if match
found
press e n t e r
key twice
Figure 12-42
To Enter Code for the keyPressed() Function
Table 12-39 shows the code to create a JavaScript user-defined function, keyPressed(), so that if the enter
key is pressed, it calls the findItem() user-defined function.
Table 12-39 Code for the keyPressed() User-Defined Function
Line
Code
34
function keyPressed(k) {
35
var hitEnter=event.keyCode
36
if (hitEnter==13) findItem()
37
}
 
Search WWH ::




Custom Search