Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML Select and Text Input

We have all seen countless instances of forms with a select drop down having one of it's options as "Other" and on choosing that option, we get to see a input text box (which was hidden all along) asking us to type in our input.

Is there a better way to implement this? Are there plugins out there which will let me do this better? Or are standard HTML elements suffice (some setting to a select tag, may be) ?

like image 450
Vijay Dev Avatar asked Aug 20 '26 08:08

Vijay Dev


1 Answers

You could use datalist. Example:

<input list="cookies" placeholder="Type of Cookie"/>

<datalist id="cookies">
    <option value="Chocolate Chip"/>
    <option value="Peanut Butter"/>
    <option value="Raisin Oatmeal"/>
</datalist>

Fiddle: http://jsfiddle.net/joshpauljohnson/Uv5Wk/

This gives the user the ability to select from a list of cookies and, if the type of cookie they seek is not found in the list, enter their own.

My only beef with it in your situation is that it may not be immediately obvious to the user they can use it as a drop down. But that could be easily remedied with a little bit of css.

like image 96
Josh Johnson Avatar answered Aug 21 '26 22:08

Josh Johnson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!