Chapter 9. Autocompletion
Autocompletion is a mechanism frequently used in modern websites to provide the user with a list of suggestions for the beginning of the word he has typed in a text box. He can then select an item from the list, which will be displayed in the input field. This feature prevents the user from having to enter an entire word or a set of words.
Basic Principles of Autocompletion
Suppose we want to write the HTML code to display the list of suggestions shown in Figure 9-1, which appears when users type the letter “p.” This displays a list in which each element contains at least one letter “p.”
Figure 9-1. List of suggestions
The input field is represented by an
<input> whose ID is
<script> tag of the
HTML page, we need to indicate both the list of suggestions (
var books) and that the input field must be observed in order to display the list ...