How to prevent ` is showing options that should be `display: none;` even the developer tool shows that.. strange. Update: Check this in Firefox. When you open the second select under "readonly" (not multiple) and select one, it will suddenly hide the first elements that should be hidden right away. – Nico O Jul 10 '14 at 17:46

  • 1
    how about keeping the whole list in JavaScript array, and populating the selects when needed? [Fiddle](http://jsfiddle.net/TheBanana/54rhz/2/) – Banana Jul 10 '14 at 17:47
  • well it might be a bug, but google chrome was at its 20nd version at the time that was reported. its 35 now, if in 15 releases this thing was not fixed, i think its safe to assume that it is not a bug... – Banana Jul 10 '14 at 17:54
  • 2
    @Banana I think that just means they're unwilling to fix it because only 7 people care about it. Based on your "array" suggestion [I came up with this](https://gist.github.com/mnbayazit/efb99e87718607b39917). We don't need to use an array and recreate elements, but we do need to maintain a reference to the options outside of the DOM. This should maintain any attributes, classes and whatever else was added to the option. – mpen Jul 10 '14 at 18:15
  • 2 Answers2

    3

    It's a bug (thanks Nico for finding this) and there's no workaround (thanks Banana).

    If you want the height to be computed correctly, you have to actually remove the <options> from the DOM.

    Community
    • 1
    • 1
    mpen
    • 272,448
    • 266
    • 850
    • 1,236
    -2

    Try this:

    You can give onchange so that the code which will work.

    Here is your Answer FIDDLE

    CODE:

     <select onchange="(this.value)">
    </select>
    
    KesaVan
    • 1,031
    • 16
    • 32
    • I don't get it. Where have you defined the `showdropdown` function? – mpen Jul 10 '14 at 17:13
    • @Mark: what is wrong in my answer, that showdropdown function was given by myself. – KesaVan Jul 10 '14 at 17:14
    • 1
      i downvoted your answer, because your fiddle does not solve Mark's issue – Banana Jul 10 '14 at 17:15
    • 3
      @Banana: he asks the dropdown should have a corresponding height, here now its working fine, then why did you down vote for my answer. – KesaVan Jul 10 '14 at 17:16
    • @KesaVan because it does not, in chrome it still changes height in your fiddle. – Banana Jul 10 '14 at 17:17
    • @Banana: see friend,In my system it works fine in chrome browser, so only i posted the answer,without knowing why doing down vote, – KesaVan Jul 10 '14 at 17:20
    • @KesaVan you chose mootools framework instead of jquery, thats why it appears to you like its working, but in fact the whole code does not execute thats why the drop down height remains intact... – Banana Jul 10 '14 at 17:21
    • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/57110/discussion-between-kesavan-and-banana). – KesaVan Jul 10 '14 at 17:21