HTML select drop-down with an input field

JavascriptJqueryHtml

Javascript Problem Overview


How can I implement a select-style drop down menu in HTML with an option that is a text input?

The idea being that someone can either select from a list of predefined options, or input their own option.

Javascript Solutions


Solution 1 - Javascript

You can use input text with "list" attribute, which refers to the datalist of values.

<input type="text" name="city" list="cityname">
    <datalist id="cityname">
      <option value="Boston">
      <option value="Cambridge">
    </datalist>

This creates a free text input field that also has a drop-down to select predefined choices. Attribution for example and more information: https://www.w3.org/wiki/HTML/Elements/datalist

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionjesalView Question on Stackoverflow
Solution 1 - JavascriptOlegView Answer on Stackoverflow