Combinatix
Combinatix

Reputation: 1216

Way to control browser's built-in autocomplete list on input tag?

There is built-in autocomplete function as a part of the input element in all major browsers. It usually drops down when user starts typing. Is there a way of controlling the list? I mean something like

<input id="abc" type="text" />

<script>
    //this does not work, obviously
    var cars=["Saab","Volvo","BMW"];
    document.getElementById("abc").autocomplete.list=cars;
</script>

... without using JQuery ... It's probably dream-of feature, isn't it?

Nobody said it is not possible so far :)

Upvotes: 1

Views: 133

Answers (1)

Amitd
Amitd

Reputation: 4849

As suggested in comments try HTML5's datalist

<input type="text" id="country" list="someCountries" />
<datalist id="someCountries">
    <option label="United Stated" value="USA"></option>
    <option label="United Kingdom" value="UK"></option>
    <option label="Uruguay" value="URU"></option>
    <option label="Brazil" value="BRA"></option>
    <option label="Russia" value="RUS"></option>
</datalist>

More here

Upvotes: 2

Related Questions