I need to let users select an item from a dropdown list, but also allow them to instead enter any text, even if it doesn't match an item in the list. How can I achieve this on a web page with HTML and Javascript?
The select
field doesn't let users enter text, and the input
text field doesn't show the preferred alternatives.
All items must show if the user opens the dropdown, so it can't be a simple auto-complete that only shows matching items.
Here is a script for that: Demo, Source
Or another one which works slightly differently: link removed (site no longer exists)
try doing this
please look at following example fiddle
I know this question is already answered, a long time ago, but this is for other people that may end up here and are having trouble finding what they need. I had trouble finding an existing plugin that did exactly what I needed, so I wrote my own jQuery UI plugin to accomplish this task. It's based on the combobox example on the jQuery UI site. Hopefully it might help someone.
https://github.com/tmooney3979/jquery.ui.combify
Was looking for an Answer as well, but all I could find was outdated.
This Issue is solved since HTML5: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/datalist
If I had not found that, I would have gone with this approach:
http://www.dhtmlgoodies.com/scripts/form_widget_editable_select/form_widget_editable_select.html
You can try my implementation of editable combobox http://www.zoonman.com/projects/combobox/
Forget datalist element that good solution for autocomplete function, but not for combobox feature.
css:
html:
js (jQuery):
This works properly even when you use text input instead of number.