views:

24

answers:

1

Is there a way to determine if a given drop down is currently active and displaying it's list of options?

I am currently binding to the mousedown event of the dropdown and populating the options when the user clicks on it. Unfortunately the mousedown event fires when the user selects the option as well.

If I can determine if the drop down is already displaying it's options, then I can skip populating the options.

+1  A: 

This will tell you if the select element has options in it

In javascript

document.getElementById("mySelectElementId").options.length

In JQuery

$("#mySelectElementId")[0].options.length

Edited: OK instead of using the mousedown event try using the focus event on the select element. This will also ensure that you populate the control properly when a user uses tab to get to the select element.

John Hartsock
In my case, that will not work, since the drop down might already have values in it. The options get loaded everytime the user clicks on the drop down.
Ross Goddard
@Ross Goddard...Sounds like you really want to use the focus event not the mouse down event
John Hartsock
I tried that out and it did work.
Ross Goddard