Open the dropdown of a Select element on focus

user1021111 picture user1021111 · Oct 30, 2011 · Viewed 12k times · Source

Possible Duplicate:
How can you programmatically tell an HTML SELECT to drop down (for example, due to mouseover)?

Is it possible to open the drop down list of a Select element when the Select element gets focus?

I know it automatically focuses when you click it ... but I want it to work when you tab it too.

Answer

Dany Khalife picture Dany Khalife · Oct 30, 2011

Unfortunately the answer for your question is simply "No, its not possible with the current HTML and Javascript controls"

However, if you use jQuery and this plugin (https://github.com/fnagel/jquery-ui/wiki/Selectmenu) for select menus i believe you could do :

$("#idofSelect").selectmenu("open");

Also another alternative for your idea, but maybe not as fancy:

document.getElementById("idOfSelect").setAttribute("size", 5);

What this does is simply make it a multiline select, so in some way it displays the options... You could do this on focus, and then do another event on click where you reset its size to 1 and stop the event propagation (so that onfocus doesn't get called after..) but like i said, this is THAT professional, so either live with your select the way it is, or switch to jQuery select menus and have fun opening and closing them dynamically at your will :)