Html select with options as textboxes - html

I am writing an select drop down in html which has
<option><input type="text"></option>
But when I am running that program the textbox is coming out of the dropdown,the purpose of inserting text box in select is that , If a user is unable to find its desired option . He will be able to add a new one.
This is the select code. You can see alive demo running this code http://jsfiddle.net/_nikhilagrawal/eJ7k6/3/. Why this input type text is coming outside the select. Please have a look.
<select name="color">
<option>pick a color</option>
<option value="red">RED</option>
<option value="blue">BLUE</option>
<option><input type="text" name="color" /></option>
</select>
This is the output of the drop down.

<option> elements cannot have anything other than text inside them.
If you want a widget that combines text inputs with a dropdown menu then you will have to build it using JavaScript.

You can not write
<input type="text" name="color" />
inside <option></option> tag.
You should add textbox nearest to selectbox If a user is unable to find its desired option,user can add new one. or you need to customize your select box using css+jquery

Related

Is there a way to disable text for a drop down menu?

I'm trying to make a text field that has a drop down menu, but the user is only able to select options from the drop down menu. I want to disable the user's ability to type in the text box, while still allowing them to select an option, but I don't know how to do that. I've tried disable and readonly, but neither do what I want, although it is possible that I am using these attributes wrong.
Edit
I realized two mistakes in my original question. I meant disabled instead of disable, and I also meant text input instead of text field.
Why you want to have a text field, you can simply use select tag
<label for="cars">Choose a car:</label>
<select name="cars" id="cars" oninput="myFunc(this)">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
This will create a dropdown.
You can attach the value to a div to show it
function myFunc(selected){
//you can replace the divId below by your div's id
document.getElementById("divId").innerHTML=selected.value;
}
Or you can use input type="radio"

How can I keep datalist showing items in the drop down menu?

If I use the normal datalist, for example, like this.
<input name="example" list="example" />
<datalist id="example">
<option value="Value1"></option>
<option value="Value2"></option>
</datalist>
When I click on an item, it starts only showing that element. And I can't go back to see all the items. How can I fix that?
Note that I don't want to use select either, because it doesn't allow me to copy an entry.
That is one of Datalist's limitations, but there are some workarounds: http://pebbleroad.github.io/combo-select/

Getting the full list from a HTML Datalist clicking on the arrow

If a item is selected it is not possible to see the full list by cliking the arrow as shown in the diagram.
<div>
<input type="text" id="client" list="allclients" placeholder="Start typing..." value="" />
<datalist id="allclients">
<select>
<option value="Jack">Jack</option>
<option value="John">John</option>
</select>
</datalist>
</div>
If the user select one he cannot see the full list unless input is cleared again. Is there a way to get rid of this limitaion.
This is the expected behavior and what I asked is not possible. The list supposed to get filter by the user input text.
Possible solutions for this issue can be solved using one of these
http://pebbleroad.github.io/combo-select/
http://jqueryui.com/autocomplete/#combobox

SELECT2 Input Box Styling

I am using a SELECT2 Input box. I need help trying to change the color (to white) of the "X" that would remove the tag from the field. I have included a fiddle with some sample code.
The below is just some sample code. I am using an input box with angular utilizing ui-select2 functionality. I figure is someone can figure out below, I can at least translate it to what I need. Thanks!
<select multiple id="e1" style="width:300px">
<option value="AL">Alabama</option>
<option value="Am">Amalapuram</option>
<option value="An">Anakapalli</option>
<option value="Ak">Akkayapalem</option>
<option value="WY">Wyoming</option>
</select>
<input type="checkbox" id="checkbox" >Select All
Some Script:
$("#e1").select2();
http://jsfiddle.net/jimfromthegym/jEADR/1112/
It appears that the "X" is actually an image: select2.png
If you check your browser web tools network tab you can see this external resource loaded.
I'm assuming it is part of the select2 plugin you are using. If you can find this image in the source of the plugin and change the color manually using an image editor that would be your quick fix/change.

How to input text in HTML Select Tag?

I want to make input option in select tag so user can choose between options or insert different value.
Is it possible?
<select>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
**<insert user value>**
</select>
HTML solution with "list" attribute:
<input type="text" name="city" list="citynames">
<datalist id="citynames">
<option value="Boston">
<option value="Cambridge">
</datalist>
You will have to use javascript to get the additional value. Check this post for some example code:
Jquery dynamically update "other" option in select
Select elements can't contain anything other than option or optgroup elements. Here's a ref to the spec http://www.w3.org/TR/html5/forms.html#the-select-element
You may be better off adding an option for "other" in your dropdown and then using JS to detect for that choice to dynamically show an input (below the dropdown) for a custom value.
Position an input box over the select box and remove the border of the input box. Make the length of the input box shorter than the select box so that the select box may still be used at its end.
Use the oninput event to detect input being entered in the input box. On each keystroke check for a continuing match in the select box. When a match no longer exists there is no further need for the select box.
The server will expect to receive both the text box input, if any, and the select box input, if any, and should use the select value if provided otherwise the input value if provided.