For this dropdownlist in HTML:
<select id="countries">
<option value="1">Country</option>
</select>
I would like to open the list (the same as left-clicking on it). Is this possible using JavaScript (or more specifically jQuery)?
-
It is not possible for javascript to "click" on an element (u can trigger the attached
onclickevent, but you can't literally click it)To view all the items in the list, make the list a
multiplelist and increase its size, like such:<select id="countries" multiple="multiple" size="10"> <option value="1">Country</option> </select>Grant Wagner : Adds a scrollbar after 4 items in IE6, 7 & 8b2 and Opera 9.62. Adds a scrollbar after 10 items in Safari for Windows and Google Chrome. -
You can easily simulate a click on an element, but a click on a
<select>won’t open up the dropdown.Using multiple selects can be problematic. Perhaps you should consider radio buttons inside a container element which you can expand and contract as needed.
-
As has been stated, you can't programmatically open a
<select>using JavaScript.However, you could write your own
<select>managing the entire look and feel yourself. Something like what you see for the autocomplete search terms on Google or Yahoo! or the Search for Location box at The Weather Network.I found one for jQuery here. I have no idea whether it would meet your needs, but even if it doesn't completely meet your needs, it should be possible to modify it so it would open as the result of some other action or event. This one actually looks more promising.
-
No you can't.
You can change the size to make it larger... similar to Dreas idea, but it is the size you need to change.
<select id="countries" size="6"> <option value="1">Country 1</option> <option value="2">Country 2</option> <option value="3">Country 3</option> <option value="4">Country 4</option> <option value="5">Country 5</option> <option value="6">Country 6</option> </select>
0 comments:
Post a Comment