Quick Tip – Autocomplete Using HTML5 Datalist Element
Using Datalist Element
The result of running the page will be:
Creating On The Fly Datalist
As you can see you have a predefined array with the same cities options from the previous code sample. The fillDataList function is called when the DOM content loaded event is fired. In the fillDataList, all you have to do is to get the container element (that must be a phrasing element) and append to it the created datalist. This example can be changed easily to use data retrieved from the server-side.
Datalist Browser Support
As in all new HTML5 elements, currently the datalist isn’t supported in all of the browsers. The datalist is supported in Chrome from version 20, in Firefox from version 4, in Internet Explorer from version 10 and in Opera from version 9. You can go to the following web page to see where the datalist is supported in more details.