Skip to content
Advertisement

How to set default value in input datalist and still have the drop down?

I am using the datalist HTML property to get a drop down inout box:

JavaScript

The problem is that now I have to clear the input box to view all the drop down values. Is there a way to have a default value but still view all the values in the datalist when the drop down icon is clicked?

Advertisement

Answer

I know of no way to do this natively. You could make a “helper” div to use when the input field has value. I couldn’t hide the native drop down so I renamed the ID. Uses jQuery.

html

JavaScript

script

JavaScript

jsFiddle

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement