How to Limit the Visible Options in an HTML <Select> Dropdown

Unable set the limit of visible options in the dropdown of a select input type

As i am using bootstrap select; The solution of limiting the visible option lies here

<select class="selectpicker" data-size="5">

So in my case

 <select class="selectpicker" id="sector" name="sector" multiple
style="height: 10px; overflow-y: scroll;"

Reference :

Limiting options in select dropdown to a specific number


<select onmousedown="if(this.options.length>15){this.size=15;}" onchange='this.size=0;' onblur="this.size=0;">

Please check the working fiddle:

How to Limit the option size within 10

Referring to this answer:

<select onfocus='this.size=10;' onblur='this.size=1;'         onchange='this.blur();'>  <option>option a</option>  <option>option b</option>  <option>option c</option>  <option>option d</option>  <option>option e</option>  <option>option f</option>  <option>option g</option>  <option>option h</option>  <option>option i</option>  <option>option j</option>  <option>option k</option>  <option>option l</option>  <option>option m</option>  <option>option n</option>  <option>option o</option>  <option>option p</option>  <option>option q</option>  <option>option r</option></select>

How do I limit the number of options displayed in an HTML Select element dropdown menu?

Sadly, you can't change the item's that the dropdownlist displays, it is decided by the browser, with the size option it will loose its 'dropdownlist' form, and turn more into a list.

You could try finding some Jquery dropdown list, they are usually editable to whatever you want.

Limit displayed options in a dropdown using css

Add a class to the selects you want to change:

<select class="limit">

Then using some jQuery:

$('.limit').attr('size', 5);

Here's an example.

Related Topics

Leave a reply