HTML and CSS Reference
In-Depth Information
Line 34 declares the keyPressed() user-defined function and accepts a parameter value k, which represents
the key pressed. Line 35 assigns the value of the keyCode property of the key pressed to a decimal value stored
in the variable, hitEnter. The if statement on line 36 tests if the value of hitEnter is equal to an ASCII 13, which is
the equivalent of the enter key. If hitEnter is equal to 13, meaning the enter key has been pressed, then the
findItem() user-defined function is called. The keyPressed() function is called with every press of a key until the
enter key is pressed. Line 37 closes the JavaScript function.
The following step enters the keyPressed() user-defined function.
1
If necessary, click
line 34.
Enter the code shown
in Table 12-39 to
create the keyPressed()
function. Press the
e n t e r key twice after
line 37 (Figure 12-43).
keyPressed()
user-defined
function
press e n t e r
key twice
Figure 12-43
To Enter Code for the clearField() Function
The Reset button does not automatically clear the input text field as in a normal HTML form, nor does it
clear the output area of the <div> container. Table 12-40 shows the code to create a JavaScript user-defined function
called clearField() that clears the input text field, clears the <div> container area, and sets the focus back in the
text field.
Table 12-40 Code for the clearField() User-Defined Function
Line
Code
39
function clearField() {
40
SearchText.value = “”
41
SearchResult.innerHTML = “”
42
SearchText.focus()
43
}
44
45
//-->
46
</script>
Line 39 defines the clearField() user-defined function. Line 40 clears the SearchText text field. Line 41 uses
the innerHTML to clear the SearchResult <div> container. Line 42 sets the focus and places the insertion point
back in the SearchText text field for the next entry. Lines 45 and 46 close the HTML comment and the </script>
section.
The following step enters the clearField() user-defined function.
 
Search WWH ::




Custom Search