Skip to content

How to create an autocomplete input with plain Javascript

Stephen Afam-Osemene on August 13, 2017

Now, most people who have built websites have included forms. Regular text elements, number, select (dropdown), checkboxes and radio buttons. ... [Read Full]
markdown guide

Hi, Afam
This is a great article; its good to see this implementation in Vanilla JS. But i'd like to know the reason why you are testing for this condition in your JS file




Thanks for spotting that. There's actually no reason for that in the example.
It was specific code for a project.

I'll edit.


Thank you! I need to do an autocomplete form and I had no idea where to start! 🔑


You're welcome!!!

I'm really happy that this helped


I've made this after reading you tutorial,,

it is moslty for the case you already has an existing app with , the goal here is to turn them into lightweight autocomplete input. No dependencies, plain vanilla js, based on as you teach me.

thanks it save me from a lot of refractoring on my current project.


That's great! Thanks for the feedback. I'll check your project out.


Great post - datalist is a really powerful addition to HTML5 that I was not aware of.


This is exactly what I've been looking for, so thanks for posting! I am getting a host of issues, however, and I'm a bit of a newbie with some of this (especially php) so I'm not sure what the wrench in the gears is here...

In Chrome: Failed to load file:///C:/query.php?query=N: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.

In Chrome with web server:
Uncaught SyntaxError: Unexpected token < in JSON at position 0
at JSON.parse ()
at XMLHttpRequest.window.hinterXHR.onreadystatechange (index.js:35)

In Firefox: NS_ERROR_DOM_BAD_URI: Access to restricted URI denied


Thanks for this awesome article... it was really helpful


Thanks for this! I'm trying to write a React component that does the same, this will be a huge help.


Hi! Great article!

It's worth to mention that this will not work as intended on iOS devices, the dropdown will not show.


great friend

how to make it work only with the initials of each word.

code of conduct - report abuse