21

I need to create a custom auto-complete list of suggestions for an input field. So far I have associated an event handler to the input event to the html input element, so that when that event triggers, I can fetch the suggestions.

The problem is how would I show these suggestions. By default, input elements can display suggestions, but is it possible to customize/access those suggestions?

If not, what would be the alternatives?

Preferably I would like not to use external libraries.

1 Answer 1

47

You may use 'datalist' tag but it doesn't work in IE <= 9

    <!DOCTYPE html>
    <html>
        <body>
            <form>

              <input list="country" name="countru">

              <datalist id="country">

                <option value="U.S.">
                <option value="France">
                <option value="China">
                <option value="Cambodia">
                <option value="Chile">
                <option value="Canada">
                <option value="Poland">

              </datalist>

              <input type="submit">
            </form>
        </body>
    </html>

Run the code and try typing 'C' and then 'a'.

Sign up to request clarification or add additional context in comments.

1 Comment

This is really great way of adding autocomplete in any technology without using any third party libraries. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.