I'm working on building new site, and I need a drop down menu to select the amount of something in my site. But at the same time I need this drop down list to accept text. So if the client wants to choose from the drop down list then he can, also if the client want to enter the amount by text then he can also. As you can see I want to make it dual.
For example: suppose there is an amount
drop down menu, and its elements are (1,2,3);
Suppose now that the client needs the amount to be 5 - this is his right - it does not exist in the drop down list, so the client now must enter the amount textually. So for any entry the client must either choose from the drop down list or enter the amount textually.
After the description of my problem, and the simple example that I have introduced to you, here is my question:
Is there HTML code to make a drop down menu and a text field in one, as dual, not separated?
Inspired by the js fiddle by @ajdeguzman (made my day), here is my node/React derivative:
Looks like this:
I'd like to add a jQuery autocomplete based solution that does the job.
Step 1: Make the list fixed height and scrollable
Get the code from https://jqueryui.com/autocomplete/ "Scrollable" example, setting max height to the list of results so it behaves as a select box.
Step 2: Open the list on focus:
Display jquery ui auto-complete list on focus event
Step 3: Set minimum chars to 0 so it opens no matter how many chars are in the input
Final result:
Check jsfiddle here:
https://jsfiddle.net/bao7fhm3/1/
You can do this natively with HTML5
<datalist>
:I like jQuery Token input. Actually prefer the UI over some of the other options mentioned above.
http://loopj.com/jquery-tokeninput/
Also see: http://railscasts.com/episodes/258-token-fields for an explanation
I found this question and discussion very helpful and wanted to show the solution I ended up with. It is based on the answer given by @DevangRathod, but I used jQuery and made a couple tweaks to it, so wanted to show a fully commented sample to help anyone else working on something similar. I originally had been using the HTML5 data-list element, but was dissatisfied with that solution since it removes options from the drop down list that don't match text typed in the box. In my application, I wanted the full list to always be available.
Fully functional demo here: https://jsfiddle.net/abru77mm/
HTML:
JS:
CSS:
Any comments for improvement on my implementation welcome. Hope someone finds this helpful.
Option 1
Include the script from dhtmlgoodies and initialize like this:
Option 2
Here's a custom solution which combines a
<select>
element and<input>
element, styles them, and toggles back and forth via JavaScript