Is it possible to use JS to open an HTML select to show its option list?
Unfortunately there's a simple answer to this question, and it's "No"
This works on Google Chrome
dropDown = function (elementId) {
var dropdown = document.getElementById(elementId);
try {
showDropdown(dropdown);
} catch(e) {
}
return false;
};
showDropdown = function (element) {
var event;
event = document.createEvent('MouseEvents');
event.initMouseEvent('mousedown', true, true, window);
element.dispatchEvent(event);
};
I had this problem...and found a workable solution.
I didn't want the select box to show until the user clicked on some plain HTML. So I overlayed the select element with opacity=.01
. Upon clicking, I changed it back to opacity=100
. This allowed me to hide the select, and when the user clicked the text the select appeared with the options showing.