Open SELECT dropdown list automatically

Is it possible to open a SELECT element automatically using JavaScript? (i.e., instead of the user clicking the down arrow, is there a way to get JavaScript to click it so that the list is just open)?

Thanks
LVL 8
ChumadAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hieloCommented:
save the attached code as test.html and try it:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd"> 
<html>
<head>
<title></title>
<script type="text/javascript">
function op()
{
var s = document.getElementById("theList")
s.multiple="multiple";
s.size=5;
}
</script>
</head>
<body>
<div onclick="op()">Open List</div>
<select id="theList">
<option value="1">a</option>
<option value="2">b</option>
<option value="3">c</option>
<option value="4">d</option>
</select>
</body>
</html>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
b0lsc0ttIT ManagerCommented:
Chumad,

Javascript can't "click" the select list to have it show.  The clever script above will give that effect by changing the select to a multi-select list.  Hopefully that will work and all credit to Hielo for it.  However if you want to keep the select list not multiselect then there is no way to do it.

Let me know if you have any questions or need more information.

b0lsc0tt
0
ChumadAuthor Commented:
Partial because it's a "sly" workaround for what I really needed.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.