Removing the scroll bar from a select element - html

Is there a way to remove the scroll bar in a select element with the 'multiple' attribute enabled?
<select name="test" multiple>
<option value="foo">Foo</option>
<option value="bar">Bar</option>
<option value="baz">Baz</option>
</select>

You should not remove it actually for accessibility reasons. If you do so, it would look like a textarea rather than a multi selectbox.

Related

Not displaying correct option in drop-down menu

I created a drop down list with links. It works properly except when I go back one page, then instead of the option which is 'selected' in the HTML, it shows the option I had navigated to. I would like it to reset, so that the page I'm on is the one being displayed when the list is collapsed. How can I fix this?
<div id="drop">
<select name="year" id="year" onchange="location = this.value;">
<option value="sermons-2023.html"selected>2023</option>
<option value="sermons-2022.html">2022</option>
<option value="sermons-2021.html">2021</option>
<option value="sermons-2020.html">2020</option>
<option value="sermons-2019.html">2019</option>
<option value="sermons-2018.html">2018</option>
<option value="sermons-2017.html">2017</option>
<option value="sermons-2016.html">2016</option>
<option value="sermons-2015.html">2015</option>
</select>
</div>
You have to save the value with js in localstoreg and then after returning to the previous page you can see that the value is the same

Set <option> CSS display to none doesn't hide the selected option

When I add display:none to an <option> tag with JavaScript after the page is ready, it wouldn't hide the default or the selected element, it stays on the hidden option unless I change that manually. The option 08:30 is hidden but it's still there as selected, but not an option.
Here is the HTML and there's also a screenshot:
<div class="form-floating mb-3">
<select class="form-select" id="time">
<option value="08:30" style="display: none;">08:30</option>
<option value="08:45">08:45</option>
</select>
</div>
I've tried disabling the <option> tag as well but it does the same and keeps it selected. I need it to jump into an active select option or any other option but not the one I hide or disable.
Update:
I have to use a workaround to get this working. First I've added all <option> tags to the <select> tag, then remove the ones that I don't want:
$('#time').html('
<option value="08:30">08:30</option>
<option value="08:45">08:45</option>
<option value="09:00">09:00</option>
<option value="09:15">09:15</option>
<option value="09:30">09:30</option>
<option value="09:45">09:45</option>
')
$('#time option[value="'09:00'"]').remove()
This works, although doesn't actually solve the issue (I guess that's a bug and hasn't been addressed yet). I would still appreciated an answer to improve the code.
Hello & Welcome Mohsen Salehi,
<option hidden>Hidden option</option>
It is not supported by IE < 11.
Please read more about it here How to hide a in a menu with CSS?
Edit:
You can also add disabled to prevent getting selected.
<div class="form-floating mb-3">
<select class="form-select" id="time">
<option value="08:30" style="display: none;" disabled>08:30</option>
<option value="08:45">08:45</option>
</select>
</div>

Vertical scroll in Select html

Can you have a vertical scroll in select html,,,
But keeping size="1" So when you click on the drop list it displays only around 5 options and the rest are viewed when you scroll.
I have a fiddel here
form name="#">
<div class="select-style2">
<select size="1" autocomplete="off">
<option hidden value="#">title</option>
<option value="#">2</option>
<option value="#">3 </option>
<option value="#">4 </option>
<option value="#">5 </option>
<option value="#">6 </option>
<option value="#">7 </option>
<option value="#">8 </option>
<option value="#">9 </option>
<option value="#">10 </option>
</select>
</div>
<input type="button" name="test" value="Go"
onClick="go()" id="btn">
As a previous answer points out, there isn't good styling options for select dropdowns.
However, the good news is, the answer to your question "Can you have a vertical scroll in select html" is yes. It's there by default when you have enough options in the list. But changing that number seems impossible with css.
See demo here: http://jsfiddle.net/VxNV9/1/
But you could create a custom drop down in jquery/javascript and style it however you want.
It is not possible to do in HTML. In SO, they have already discussed about this. Check It out Here.
May be there are other ways of achiving this through javascript or jQuery, with links on that page to some jQuery plugins which create a "fake" html select box that looks and behaves like one, but can have the height set.

use css to resize select tag in form to see all option tags

Is it possible to dynamicaly resize the visible options in select tag in forms? I have the example:
<select size="1">
<option value='1'>1
<option selected value='2'>2
<option value='3'>3
<option value='4'>4
</select>
I would like to have visible all options (to setup size dynamically with css) when design page for printing. And also to see selected option(s) in another design (color, bold ...). For resize I tried:
select{
size:4;
}
but it doesn't work. I need a working solution at least for FF, IE, Safari ...
Do have any idea?
Thanks in advance!
You can use this way:
<select size="1" size="4">
<option value='1'>1</option>
<option selected value='2'>2</option>
<option value='3'>3</option>
<option value='4'>4</option>
</select>​​​​​​​​​​​​
And don't forget to close the </option>

Are Multi-line Options in Html Select Tags Possible?

Is it possible (using HTML only) to display select with options that span multiple lines each?
It is not possible using html select control.
You can use a div that can act as a dropdown list using JavaScript and css.
not only is it not possible on standard html, but it would then (as an object) become incompatible with the way IOS devices handle the option tag, which is to display a scroll list so it is not even reasonable to want the option tag to behave that way as it would break cross-device compatibility badly and unexpectedly.
as others have answered (i dont have enough reputation to upvote or comment yet) have said, it must be done with css/div styling etc and in that way is a lot more extensible with full html functionality within each of the option tag's as well as (via css styling) being mobile device friendly.
If your case is around iOS truncating long option text, then the solution from How to fix truncated text on <select> element on iOS7 can help.
Add an empty optgroup at the end of the select list:
You can implement like this:
<select>
<option selected="" disabled="">option first</option>
<option>another option that is really long and will probably be truncated on a mobile device</option>
...
<optgroup label=""></optgroup>
</select>
As the presentation of a select element is up to the user agent, I'm afraid you can't have that, unless some UA actually implements it. But select as either a ListBox or ComboBox never really had much need for items spanning multiple lines. Furthermore it would greatly confuse users as they are used to one line = one item.
No.
You could use radio buttons instead though, their <label>s can word wrap.
It would be possible by using some JavaScript with CSS styling on HTML elements, easily done with a framework like Dojo Toolkit. Otherwise, use Radio or Checkbox controls.
If you have lots of options and for that reason looking for multi-line possibility, then there is another trick that can be helpful. Instead of using select and option tag, use datalist and option tag. By this, users can search for their option inside the select area.
<input list="stocks" name="stockArea" placeholder="hello">
<label for="stockArea">Select Your Stock</label>
<datalist id="stocks">
<option value="Microsoft" >
<option value="Lenovo">
<option value="Apple">
<option value="Twitter">
<option value="Amazon">
</datalist>
What about:
<!DOCTYPE html>
<html>
<body>
<select size="13" multiple>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="opel">Opel</option>
<option value="audi">Audi</option>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="opel">Opel</option>
<option value="audi">Audi</option>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="opel">Opel</option>
<option value="audi">Audi</option>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="opel">Opel</option>
<option value="audi">Audi</option>
</select>
</body>
</html>
I don't know if this is what you were looking for, but maybe it could help you.
If you want to select multiple options, you must press Ctrl + click to select more options.
If you want to disable multiselect, just erase the "multiple" parameter from the SELECT tag.