Implementing an Autocomplete Input

. . . jQuery . . . $( "#autocomplete" ).autocomplete({    source: ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"] }); . . . HTML . . . <input id="autocomplete">

The autocomplete widget is attached to text input elements. As the user types in the text input, suggestions from a list are displayed. This is especially helpful when you have a finite set of possibilities that can be typed in and you want to make sure the correct spelling is used.

To apply the autocomplete widget, define a source array that contains the strings available to autocomplete in the text input. Then call the .autoComplete({source:array}) method on the input element. For example:

Get jQuery and JavaScript Phrasebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.