List Attribute html5 - html

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.

Related

Strange values in Datalist Input 'Gas' 'gas'

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

Is it possible for a datalist to have scrolldown?

I'm new to HTML and trying to use a datalist. I need to limit it to display only 5 items and the rest to be viewed using scrolldown. Is there any way?
My code :
<form>
<input list="Android" name="Android">
<datalist id="Android">
<option value="Alpha">
<option value="Beta">
<option value="Cupcake">
<option value="Doughnut">
<option value="Eclairs">
<option value="Fryo">
<option value="GingerBread">
<option value="HoneyComb">
<option value="Icecream Sandwich">
<option value="Jelly Bean">
<option value="Kitkat">
<option value="Lollipop">
<option value="Marshmallow">
<option value="Nougat">
</datalist>
<input type="submit">
</form>
This is the output of my code
Thanks in advance!
Well, that's not possible to do, the datalist layout is defined by the browser the same as it does with the select tag and there is very little flexibility on customization. Your example comes from Chrome; in Firefox, it shows only 6 items and on Edge it shows something similar with limited size as well.
The proposed solution is using something else rather that using datalist, if you can't live with the datalist design Chrome offers, try some other component with a similar behavior, like dropdown select, autocomplete, autosugest, typeahead, etc.

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>

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

Form Select List - Initially selected option not working correctly in IE

I have a form with a select list of various office locations, i have it set so it should have the office initially selected BUT it does not seem to Work in IE!!! (no surprise)
here is what i am using to preselect:
<option selected value="Office 1">Office 1</option>
here is the site: http://www.nwtaxpreparation.com/offices/122andpowell.html
let me know if you have any solutions!
HTML 4 uses:
<option value="foo" selected>Bar</option>
XHTML REQUIRES:
<option value="foo" selected="selected">Bar</option>
To say that "there is no such thing as selected="whatever" is false!
I recently had the same problem with selected options tags. I had a series of select boxes like this:
<select>
<option value="dr">Day rate</option>
<option selected="selected" value="sv">Social value</option>
</select>
<select>
<option value="dr">Day rate</option>
<option selected="selected" value="sv">Social value</option>
</select>
I couldn't work out why the correct items wouldn't select. I later discovered that it was because there was no name attribute on the select item. Firefox seems to need this to work properly, even in version 15.
<select name="type">
<option value="dr">Day rate</option>
<option selected="selected" value="sv">Social value</option>
</select>
I changed it to the above and selected="selected" works fine now.