Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript - Force select element to dropdown?

How can I force the select element to dropdown using Javascript? Is it possible?

<select id="MiamiPlayers">
    <option value="0">Bosh</option>
    <option value="1">Wade</option>
    <option value="2">LeBron</option>
</select>

<input type="button" onclick="Show()" />

<script type="text/javascript">
    function Show()
    {
        //force the select to dropdown...
    }
</script>

Thanks in advance!

like image 831
dpp Avatar asked Jun 02 '11 05:06

dpp


2 Answers

You can't open the drop down, but you can do something like this:

document.getElementById('MiamiPlayers').setAttribute('size', 3);

See http://jsfiddle.net/MdCBB/

like image 73
Petah Avatar answered Nov 11 '22 15:11

Petah


See Display DropDown options on Focus

like image 35
ari Avatar answered Nov 11 '22 16:11

ari