9

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!

1

3 Answers 3

5

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/

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, it's to bad you can't open the drop down though.
2

See Display DropDown options on Focus

Comments

0
var select = document.getElementById(id); select.size = select.options.length; 

where id is the id of the your select box...

10 Comments

That's converting a dropdown to a list. Useless in most cases.
@JorgeFuentesGonzález Could you provide a better solution for OP's task?
@malte Actually Petah answer is the correct one, as it states "You can't open the drop down, but...". Needless to add the same answer again. If you need to open it so badly, then you need to create your own select widget or use one of many existent around the Internet.
@JorgeFuentesGonzález fair enough. There are seemingly different opinions regarding that matter.
@malte Those are completely different answers talking about attributes... are you kidding me? xD The question is "Can I open a dropdown?" and "Convert the dropdown to a list" is obviously not a correct answer. That's a workaround to an unsolvable problem, but not an answer. There are important differences between a list and a dropdown... Mostly the vertical height.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.