Displaying Autocomplete Suggestions
Let's connect the data from the backend and make the suggestions visible.
We'll cover the following...
Input event listener
We’re working with just a basic input bar and a ul
inside a div
to show the list of results.
Since results show up every time the input changes, we’ll add an event listener on the input element. Whenever it changes, whether that’s a new character, a backspace or a copy-paste, this event listener should read the new value and get new results for us.
Let’s add an event listener to the input and test that it works by just having it echo the results. Usually, I’d have the output be the console (part of the browser devtools), but for demonstration purposes, writing HTML works ...