So you want to open a drop down select box without clicking on it? For years, people have been looking for the answer to this question. While everything else on the web has been changing since, the answer to this question remains the same.
Instead of wasting your time let me solidly state this for you…
Solid Tip: You cannot open a select element with a script.
What are my alternatives?
Sorry to burst your bubble back there, but it’s not possible. Better men than me have tried and failed.
Your best bet is to create your own fake select box (yeah, that same suggestion you probably have seen already), style it with CSS, and extend its functionality with JavaScript.
This basically means you make a div with an arrow graphic, add a click event to it, then pop open a box onclick that shows a stack of option divs. While it is certainly no small task, it will allow you to add any number of features that would not be possible in a normal select element like opening it using scripts or styling with full CSS support.
At least you won’t have to continue your wild goose chase looking for something that can’t be done.
>>> Solid Tip: You cannot open a select element with a script.
Of course you can
var x=document.getElementById(“MySelect”);
x.size = x.options.length;
Nope. Opening a selectbox and changing its height are worlds apart…
Glad I landed here at the beginning of my “wild goose chase”
You can by $(elem).isfocus() and then use $(elem).click();
Sean, there is no method called “isfocus” and, even if a select box is focused, a “click” method doesn’t open it.
Hey, if anyone here wants to do something SIMILAR to this, the best way is to have a select, then make an option in it with style=”display: none;”. Add some event listeners to detect the “oninput” event on the select, do some processing, then reset the value back to the invisible option. Then, style away your drop down, making it look like a button. That’s all that’s to it.