Open the dropdown of a Select element on focus

12,310

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 :)

Share:
12,310
Admin
Author by

Admin

Updated on June 16, 2022

Comments