how to display select box options without selecting select box - html

There is a requirement in my project like.,
I have select box in desktop view and in mobile only options has to be displayed.
I got stuck how to display all the options without selecting select box .
<h3>Desktop View</h3>
<select name="carmakes" id="carmakes">
<option selected='selected' value="0">Car makes</option>
<option value="bmw">BMW</option>
<option value="audi">Audi</option>
</select>
<br/><br/><br/><br/>
<h3>Mobile View</h3>
<option selected='selected' value="0">Car makes</option>
<option value="bmw">BMW</option>
<option value="audi">Audi</option>
Thanks
Demo

Just give multiple for your select box and it'll display like that...
<select multiple name="carmakes" id="carmakes">
<option selected='selected' value="0">Car makes</option>
<option value="bmw">BMW</option>
<option value="audi">Audi</option>
</select>

Related

Coloured boxes in select options

I wan't to do like coloured boxes in select options:
<select name="" id="dfads">
<option value="">-</option>
<option value="a"><span style="background:red">##</span> A</option>
<option value="b">B</option>
<option value="c">C</option>
</select>
The background work doesn't work in select option. Is it possible such simply?

how to put multiple values in an option?

I have a select with values like van, economy, economy-citroen. I select the van option and it displays the vans, however I would like to make an option that calls the van and economy values at the same time (not the multiple select version).
Something like value="economy van".
<select id="car_type" class="car_type span12">
<option value="-1" selected="selected">Any</option>
<option value="economy">Economy</option>
<option value="economy-citroen">Economy</option>
<option value="premium">Premium</option>
<option value="standard">Standard</option>
<option value="van">Van</option>
</select>
I would like to make it like:
<select id="car_type" class="car_type span12">
<option value="-1" selected="selected">Any</option>
<option value="economy">Economy</option>
<option value="economy-citroen">Economy</option>
<option value="premium">Premium</option>
<option value="standard">Standard</option>
<option value="van">Van</option>
<option value="van economy">Economy Van</option> ---so it displays both the economy and vans
</select>
Use this
<select multiple>
<!-- options here -->
</select>
Using this, you'll be able to select multiple options for that select element.
To read more on the HTML element select please refer the Mozilla Developer Network's document
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select
Add the multiple attribute to the select element.

How to add a title to a html select tag

How would I go about setting a title in select tag? Here is my select box:
<select>
<option value="sydney">Sydney</option>
<option value="melbourne">Melbourne</option>
<option value="cromwell">Cromwell</option>
<option value="queenstown">Queenstown</option>
</select>
When I visit the site, by default it shows "Sydney". But I want to display a title, such as, "What is the name of your city?"
<select>
<option selected disabled>Choose one</option>
<option value="sydney">Sydney</option>
<option value="melbourne">Melbourne</option>
<option value="cromwell">Cromwell</option>
<option value="queenstown">Queenstown</option>
</select>
Using selected and disabled will make "Choose one" be the default selected value, but also make it impossible for the user to actually select the item, like so:
<select>
<optgroup label = "Choose One">
<option value ="sydney">Sydney</option>
<option value ="melbourne">Melbourne</option>
<option value ="cromwell">Cromwell</option>
<option value ="queenstown">Queenstown</option>
</optgroup>
</select>
You can combine it with selected and hidden
<select class="dropdown" style="width: 150px; height: 26px">
<option selected hidden>What is your name?</option>
<option value="michel">Michel</option>
<option value="thiago">Thiago</option>
<option value="Jonson">Jonson</option>
</select>
Your dropdown title will be selected and cannot chose by the user.
You can use the following
<select data-hai="whatup">
<option label="Select your city">Select your city</option>
<option value="sydney">Sydney</option>
<option value="melbourne">Melbourne</option>
<option value="cromwell">Cromwell</option>
<option value="queenstown">Queenstown</option>
</select>
I think that this would help:
<select name="select_1">
<optgroup label="First optgroup category">
<option selected="selected" value="0">Select element</option>
<option value="2">Option 1</option>
<option value="3">Option 2</option>
<option value="4">Option 3</option>
</optgroup>
<optgroup label="Second optgroup category">
<option value="5">Option 4</option>
<option value="6">Option 5</option>
<option value="7">Option 6</option>
</optgroup>
</select>
<option value="" selected style="display:none">Please select one item</option>
Using selected and using display: none; for hidden item in list.
You can add an option tag on top of the others with no value and a prompt like this:
<select>
<option value="">Choose One</option>
<option value ="sydney">Sydney</option>
<option value ="melbourne">Melbourne</option>
<option value ="cromwell">Cromwell</option>
<option value ="queenstown">Queenstown</option>
</select>
Or leave it blank instead of saying Choose one if you want.
Typically, I would suggest that you use the <optgroup> option, as that gives some nice styling and indenting to the element.
The HTML element creates a grouping of options within a element. (Source: MDN Web Docs: <optgroup>.
But, since an <optgroup> cannot be a selected value, you can make an <option selected disabled> and then stylize it with CSS so that it behaves like an <optgroup>....
.optionGroup {
font-weight: bold;
font-style: italic;
}
<select>
<option class="optionGroup" selected disabled>Choose one</option>
<option value="sydney" class="optionChild"> Sydney</option>
<option value="melbourne" class="optionChild"> Melbourne</option>
<option value="cromwell" class="optionChild"> Cromwell</option>
<option value="queenstown" class="optionChild"> Queenstown</option>
</select>
With a default option having selected attribute
<select>
<option value="" selected>Choose your city</option>
<option value ="sydney">Sydney</option>
<option value ="melbourne">Melbourne</option>
<option value ="cromwell">Cromwell</option>
<option value ="queenstown">Queenstown</option>
</select>
The first option's text will always display as default title.
<select>
<option value ="">What is the name of your city?</option>
<option value ="sydney">Sydney</option>
<option value ="melbourne">Melbourne</option>
<option value ="cromwell">Cromwell</option>
<option value ="queenstown">Queenstown</option>
</select>
You can create dropdown title | label with selected, hidden and style for old or unsupported device.
<select name="city" >
<option selected hidden style="display:none">What is your city</option>
<option value="1">Sydney</option>
<option value="2">Melbourne</option>
<option value="3">Cromwell</option>
<option value="4">Queenstown</option>
</select>
I added a <div> and it worked fine
<div title="Your title here!">
<select>
<option value="sydney">Sydney</option>
<option value="melbourne">Melbourne</option>
<option value="cromwell">Cromwell</option>
<option value="queenstown">Queenstown</option>
</select>
</div>
<select name="city">
<option value ="0">What is your city</option>
<option value ="1">Sydney</option>
<option value ="2">Melbourne</option>
<option value ="3">Cromwell</option>
<option value ="4">Queenstown</option>
</select>
You can use the unique id for the value instead

Second HTML option load by default

In an HTML select element, is it possible to have the second option selected by default?
<select class="styled" onchange="location = this.options[this.selectedIndex].value;">
<option value="9u.html">Team 9u</option>
<option value="10u.html">Team 10u</option>
<option value="11u.html">Team 11u</option>
<option value="12u.html">Team 12u</option>
<option value="13u.html">Team 13u</option>
<option value="14u.html">Team 14u</option>
<option value="15u.html">Team 15u</option>
<option value="16u.html">Team 16u</option>
</select>
I would like the value "10u" to be in the select box when I load the page.
Use the selected attribute. Is google down?
<option value="10u.html" selected>Team 10u</option>

how to set a default prompt when nothing selected for "select" using css

Is it possible to set a default prompt when nothing is selected for select box using css? or is there an elegant way to deal with this other than
<option>Select Here</option>?
Try this:
<select>
<option value="" disabled>Select one--</option>
<option value="someVal1">Option 1</option>
<option value="someVal2">Option 2</option>
<option value="someVal3">Option 3</option>
<option value="someVal4">Option 4</option>
</select>
The accepted answer did not work for me as expected.
If you need the "Select one option" to be the selected one by default , this worked for me
<select id="selected_option" name="selected_option">
<option value="default" selected="selected">Select one option </option>
<option value="someVal1">Option 1</option>
<option value="someVal2">Option 2</option>
<option value="someVal3">Option 3</option>
<option value="someVal4">Option 4</option>
</select>
Is also important that the select has id and name so when you submit the form the value will be part of the POST or GET
<select>
<option style="display:none">Empty</option>
<option>button1</option>
<option>button2</option>
</select>
This is how I use for setup the default prompt but it will not set a default value. It use a HTML5 validation required. It may be a little bit shift from the question but I hope it could help as alternative.
<select id="car" name="car[brand]" required>
<option disabled selected>Select Car Brand</option>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="opel">Opel</option>
<option value="audi">Audi</option>
</select>
Try using option with unset value
<select>
<option value>Select something</option>
<option value="1">Foo</option>
<option value="2">Bar</option>
</select>