Is it possible to use JavaScript to open an HTML select to show it's option list?
views:
705answers:
5Unfortunately there's a simple answer to this question, and it's "No"
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.
At least in Geckos this might be possible. Look here:
- https://developer.mozilla.org/en/DOM/element.dispatchEvent
- https://developer.mozilla.org/en/DOM/document.createEvent
- https://developer.mozilla.org/en/DOM/event.initMouseEvent
edit: I couldn't get this to work; seems like Gareth is correct...
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
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.