Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open the dropdown of a Select element on focus [duplicate]

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.

like image 522
user1021111 Avatar asked Nov 27 '22 11:11

user1021111


1 Answers

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

like image 196
Dany Khalife Avatar answered Dec 05 '22 03:12

Dany Khalife