views:

705

answers:

5

Is it possible to use JavaScript to open an HTML select to show it's option list?

+4  A: 

Unfortunately there's a simple answer to this question, and it's "No"

Gareth
sure about that?
Christoph
Can't be done (with plain html/javascript)
scunliffe
+2  A: 

I'm fairly certain the answer is: No. You can select options with JavaScript but not open the select. You'd have to use a custom solution.

Eric Wendelin
+1  A: 

At least in Geckos this might be possible. Look here:

edit: I couldn't get this to work; seems like Gareth is correct...

Christoph
A: 

I had this problem...and found a workable solution.
I didn't want the select box to show until the user clicked on some plain html. So I overlayed the select element with "opacity=.01". Upon clicking, I changed it back to "opacity=100". This allowed me to hide the select, and when the user clicked the text the select appeared with the options showing.

Phil

Phil
Isn't that just hiding/showing the actual select field? The question is about showing/opening the options list.
Darryl Hein
My method does show show/open the options list along with the select box itself. The only way to open the options list is to have the select box clicked. Which I accomplished by invisibly overlaying the select on top of some target text.
Phil
+2  A: 

I use this... but it requires the user to click on the select box...

Here are the 2 javascript functions

function expand(obj)
{
    obj.size = 5;
}
function unexpand(obj)
{
    obj.size = 1;
}

then i create the select box

<select id="test" multiple="multiple" name="foo" onFocus="expand(this)" onBlur="unexpand(this)">
<option >option1</option>
<option >option2</option>
<option >option3</option>
<option >option4</option>
<option >option5</option>
</select>

I know this code is a little late, but i hope it helps someone who had the same problem as me.

ps/fyi i have not tested the code above (i create my select box dynamically), and the code i did write was only tested in FireFox.

Jason de Belle
+1, done similar things before, I believe I also set it's position to absolute when it was expanded so it didn't break document flow, and back to block when it was collapsed.
Chad
Hey thanks Chad,Your comments just helped me solve an issue!Wish i could +1 you back ;)
Jason de Belle
In my case it wouldn't solve the problem exactly, but it would be an option. +1
Darryl Hein