Reputation: 458
How can I create input type="text"
with <select></select>
option. In other words I would like to have one field where can I input text, but if I want I could choice option from dropdown list from all values just like with select
tag. Is it possible?
Upvotes: 1
Views: 53
Reputation: 13735
If you want to allow free-text typing with suggestions/pre-defined choices then I would encourage you to look at the HTML5 datalist element (see https://developer.mozilla.org/en-US/docs/HTML/Element/datalist) which is designed for precisely this purpose.
As browser support for this is limited to more recent versions of browsers (and not available at all in Safari, iOS or Android) you'll probably want to Polyfill this with something like JQuery UI autocomplete (see http://jqueryui.com/autocomplete/).
Upvotes: 2
Reputation: 3606
Not as a built in html control, no. You would need to create one using an input field and another element (such as a div or list) which contains the dropdown values, with javascript gluing the component parts together. There are plenty of tutorials on how to do this dotted around Google.
Upvotes: 1