Skip to content
Advertisement

Can you set the text of an autocomplete?

Let’s say i have an element like the foregoing:

<input id="userName">

Is it possible to set an autocomplete string and then do:

document.getElementById('userName').autocomplete = true;

Advertisement

Answer

It is not possible directly, but there is a hack for that… like this:

<form>
   <input list="autocomplete_list" name="my_input" />
   <datalist id="autocomplete_list">
       <option value="hello">
       <option value="hi">
       <option value="what's up">
   </datalist>
   <input type="submit">
</form>
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement