Skip to content Skip to sidebar Skip to footer

Limiting Options In Select Dropdown To A Specific Number

I have a dropdown list, of the options in dropdown list is less than or equal to 10 this will display all the available options but if the number of options is more than 10 then th

Solution 1:

HTML Code

<selectonmousedown="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

Solution 2:

As gcampbell noted, this is the job of the browser and cannot be influenced. If you want it to style, you have to create your own menu. For example:

<div id="menu">
<p>1</p>
...
</div>

p{height:10px}
#menu{height:100px;overflow:scroll;}

Post a Comment for "Limiting Options In Select Dropdown To A Specific Number"