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">
...
</select>
So in my case
<select class="selectpicker" id="sector" name="sector" multiple
style="height: 10px; overflow-y: scroll;"
data-live-search="true"
data-size="10">
Reference : https://developer.snapappointments.com/bootstrap-select/examples/
Limiting options in select dropdown to a specific number
HTML Code
<select onmousedown="if(this.options.length>15){this.size=15;}" onchange='this.size=0;' onblur="this.size=0;">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
<option>10</option>
<option>11</option>
<option>12</option>
<option>13</option>
<option>14</option>
<option>15</option>
<option>16</option>
<option>17</option>
<option>18</option>
<option>19</option>
<option>20</option>
<option>21</option>
<option>22</option>
<option>23</option>
<option>24</option>
<option>25</option>
</select>
Please check the working fiddle:
Demo
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">
...
</select>
Then using some jQuery:
$('.limit').attr('size', 5);
Here's an example.
Related Topics
How to Rotate the Block Every Time You Click on the Button
How to Avoid Page Break Inside Table Row for Wkhtmltopdf
How to Create an HTML Table With a Fixed/Frozen Left Column and a Scrollable Body
How to Toggle Mat-Expansion-Panel With Button Click
Make Container Shrink-To-Fit Child Elements as They Wrap
How to Append Querystrings to a Url on Submit of a Form
Best Way to Create Video from Html5 Animation
Angular 8 Material Dialog Close Button With X Top Right
How to Use CSS to Show on Hover Tool-Tips Using the Same Text Which Is Shortend With Ellipses
Large File Upload Though HTML Form (More Than 2 Gb)
How to Divide a Page in Three Vertical Sections
Angular 2: Get Position of HTML Element
How to Make Sure This Stays Centered, Even When Zoomed Out or In
Why Align Items Center Not Working
Bootstrap Accordion Issue With Arrow
How to Make Bootstrap 4 Cards the Same Height in Card-Columns