6

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.

Community
  • 1
  • 1
user1021111
  • 61
  • 1
  • 1
  • 2

2 Answers2

2

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

Dany Khalife
  • 1,850
  • 3
  • 20
  • 47
  • Thanks for getting back, Dany. I'm showing my ignorance ... how do you link to this plugin in an HTML page? – user1021111 Oct 31 '11 at 12:08
  • my pleasure, what you need to do is go to the link above the guide can help you how the plugin works, and to install it, download the latest stable release and in the zip you get, look for file `jquery.selectmenu.js` in the `ui` folder then copy this file to your project folder and include it in your file like so : `` let me know if you have any problems – Dany Khalife Oct 31 '11 at 16:07
  • 2
    If it can be done in jquery it can be done in javascript – aintnorest Sep 26 '14 at 17:26
-2

As a starting point, if using JQuery you could use the trigger function eg If your select box has an id of "names" simply call $('#names').trigger('click');

Crashdesk
  • 665
  • 8
  • 27