Strange values in Datalist Input 'Gas' 'gas' - html

If I set the name or id of an Input with a list like 'cia' two strange selectable values appear at the bottom of it. Gas and gas.
Any idea why?
<input list="browsers" id="cia">
<datalist id="browsers">
<option value="Internet Explorer">
<option value="Firefox">
<option value="Chrome">
<option value="Opera">
<option value="Safari">
</datalist>
Fiddle https://jsfiddle.net/fredsaavedra/ktwrpjby/

You might have typed it into a datalist with the same ID before and your browser has cached it. Try incognito mode and they should be gone.
You can try and prevent caching with the answers mentioned here
How to turn off autocomplete while keep using datalist element in html

Related

FireFox datalist does not open until double click

<input list="browsers" name="myBrowser" />
<datalist id="browsers">
<option value="Chrome">
<option value="Firefox">
<option value="Internet Explorer">
<option value="Opera">
<option value="Safari">
</datalist>
In Chrome/Edge/Safari, clicking on this input once, opens the datalist. However in FireFox, it requires a second click on the input element to open the datalist. Is there a way to get this behavior consistent with other browsers?
The expected result is for a single click to open the data list, just as works in other browsers.

HTML Datalist shows extra options separated by horizontal line

I am passing 10 options to datalist which are displayed fine in dropdown.
But sometime I am getting couple of more options separated by horizontal line at the bottom of option list(Chrome might be cacheing or displaying some option repeated). I am not able to get why chrome is showing these extra options separated by horizontal line
I went through different articles available on internet related to datalist and I came to know that datalist accepts autocomplete attribute. It give me a hint that extra options(might be - Previous searches, suggestions) I am getting are might be due to autocomplete feature of datalist, So I tried setting it to "off".
Now I am not getting those extra option and horizontal line in option list anymore.
E.g. code snippet -
<input list="browsers" autocomplete="off">
<datalist id="browsers">
<option value="Internet Explorer">
<option value="Firefox">
<option value="Chrome">
<option value="Opera">
<option value="Safari">
</datalist>
I also came across one more attribute which datalist accepts, autocorrect="off". But I do not needed this attribute to resolve above problem.
option.select-hr { border-bottom: 1px dotted #000; }
<select name="test">
<option val="a">A</option>
<option val="b" class="select-hr">B</option>
<option val="c">C</option>
<option val="d">D</option>
</select>
But generally speaking, the only method is to put an option in with dashes, and try to make it unselectable.
<select name="test">
<option val="a">A</option>
<option val="b">B</option>
<option disabled="disabled">----</option>
<option val="c">C</option>
<option val="d">D</option>
</select>

HTML Datalist Tag - Match Beginning Of String Only

I want to use an HTML datalist tag drop-down, but only want the options that match to correspond to the beginning of the string entered. For example:
<label>Choose a browser from this list:
<input list="browsers" name="myBrowser" /></label>
<datalist id="browsers">
<option value="Chrome">
<option value="Firefox">
<option value="Internet Explorer">
<option value="Opera">
<option value="Safari">
<option value="Microsoft Edge">
</datalist>
If you type in "O" into the search bar, rather than just showing "Opera" as a result, it will show every result with an "o". Checking for other answers, I found this question: How to make datalist match result from beginning only, and the answer comes quite close, but won't suggest the result until it's finished ("O", "Op", "Ope", etc.) won't display "Opera"; only typing in the full word will show the result.

List Attribute html5

I have to make some list attributes. I found an example on w3schools, that actually shows exact like the code I want. I can see that it is not supported in Safari and IE9 and down. Is there any script you can put in my code, so I can use this code, or what do I have to use if my datalist has to be supported by all browsers?
<input list="browsers">
<datalist id="browsers">
<option value="Internet Explorer">
<option value="Firefox">
<option value="Chrome">
<option value="Opera">
<option value="Safari">
</datalist>
It seems that you don't need users to type anything, so why not to use a simple select element?
The select element is supported by all browsers and it is really similar to use. Below is an example:
<select>
<option value="ie">Internet Explorer</option>
<option value="firefox">Firefox</option>
<option value="chrome">Chrome</option>
<option value="opera">Opera</option>
<option value="safari">Safari</option>
</select>
If you need more information you can see it here: http://www.w3schools.com/tags/tag_select.asp
If you want to know the difference between the select and the datalist you can read this:
HTML Form: Select-Option vs Datalist-Option
I used bootstrap framework for it instead.

Css Auto complete for Select option

I am trying to achieve a auto complete function by Css For Select Option so Beginner of web i could't it find any sample example for this.could some provide any idea or solution
For example::
In a select box by mention of class name like
<select id="productline" class="Auto-select on">
<option value="Motorcycles">Motorcycles</option>
<option value="Planes">Planes</option>
<option value="Ships">Ships</option>
<option value="Trains">Trains</option>
</select>
Try this.
The <datalist> element specifies a list of pre-defined options for an <input> element.
The <datalist> element is used to provide an "autocomplete" feature on <input> elements. Users will see a drop-down list of pre-defined options as they input data.
Use the <input> element's list attribute to bind it together with a <datalist> element.
<input list="browsers">
<datalist id="browsers">
<option value="Internet Explorer">
<option value="Firefox">
<option value="Chrome">
<option value="Opera">
<option value="Safari">
</datalist>
Fiddle Demo