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)?
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
onclick
event, but you can't literally click it)To view all the items in the list, make the list a
multiple
list and increase its size, like such:I've come across the same problem and I have a solution. A function called ExpandSelect() that emulates mouse clicking on "select" element, it does so by creating an another
<select>
element that is absolutely posioned and have multiple options visible at once by setting thesize
attribute. Tested in all major browsers: Chrome, Opera, Firefox, Internet Explorer. Explanation of how it works, along with the code here:Edit (link was broken).
I've created a project at Google Code, go for the code there:
http://code.google.com/p/expandselect/
Screenshots
There is a little difference in GUI when emulating click, but it does not really matter, see it for yourself:
When mouse clicking:
MouseClicking http://expandselect.googlecode.com/hg/mouseclick_manyoptions.jpg
When emulating click:
EmulatingClicking http://expandselect.googlecode.com/hg/emulateclick_manyoptions.jpg
More screenshots on project's website, link above.
I was trying to find the same thing and got disappointed. I ended up changing the attribute size for the select box so it appears to open
and then when you're finished
Simple an easy way.
Now you can call your DropDown just like this
Works perfect for me.
Maybe better, because you have no problems with the position of the other elemts on the page.
Change the ID to a fix value mybe not smart but i hope you see the idee.
Maybe late, but this is how i solved it: http://jsfiddle.net/KqsK2/18/
One thing that this doesn't answer is what happens when you click on one of the options in the select list after you have done your size = n and made it absolute positioning.
Because the blur event makes it size = 1 and changes it back to how it looks, you should have something like this as well
Also, if you're having issues with the absolute positioned select list showing behind other elements, just put a
or something like that in the style of the select.