From: nick on
Anyone know how I can "pop open" a <select> element dropdown list with
javascript, so the options can be seen, just as if the user had
clicked on it?

I thought about doing it by triggering a click event or focusing the
element and then triggering a keypress, but I'm not sure if those
things are actually doable, much less how to do them. Any help would
be appreciated.
From: Laser Lips on
On May 7, 7:23 am, nick <nick...(a)fastmail.fm> wrote:
> Anyone know how I can "pop open" a <select> element dropdown list with
> javascript, so the options can be seen, just as if the user had
> clicked on it?
>
> I thought about doing it by triggering a click event or focusing the
> element and then triggering a keypress, but I'm not sure if those
> things are actually doable, much less how to do them. Any help would
> be appreciated.

I do not think it is possible.

Graham
From: nick on
On May 7, 12:00 pm, Laser Lips <loudsphi...(a)gmail.com> wrote:
> I do not think it is possible.

That makes me sad.

Second opinions?
From: Garrett Smith on
nick wrote:
> On May 7, 12:00 pm, Laser Lips <loudsphi...(a)gmail.com> wrote:
>> I do not think it is possible.
>
> That makes me sad.
>
> Second opinions?
Calling focus() on an option does not bring it into focus.

Dispatching a click event or mousedown event doesn't pop the select open.

Seems to be not possible.
--
Garrett
comp.lang.javascript FAQ: http://jibbering.com/faq/
From: SAM on
Le 5/7/10 8:23 AM, nick a �crit :
> Anyone know how I can "pop open" a <select> element dropdown list with
> javascript, so the options can be seen, just as if the user had
> clicked on it?
>
> I thought about doing it by triggering a click event or focusing the
> element and then triggering a keypress, but I'm not sure if those
> things are actually doable, much less how to do them. Any help would
> be appreciated.


You can only click forms' buttons by JS
(buttons = button, input-image, reset, submit)
The only way to click a selectbox's option could be to simulate a select



quick and not finish example :

<script type="text/javascript">
function clickMenu(menuIndex) {
var m = document.getElementById('test'),
c = m.className=='';
s = m.getElementsByTagName('BUTTON'),
n = s.length;
m.className = c? 'vu' : '';
for(var i in s) s[i].className = '';
s[menuIndex].className = 'vu';
if(c) s[menuIndex].click();
}
function blurMenu() {
var a = arguments[0];
alert('choice = '+a.innerHTML);
setTimeout(function() {a.parentNode.className='';},1000)
}
</script>
<style type="text/css">
#test button { width: 100%; text-align:center;border:3px inset;
background:#fff; display: none }
#test.vu button,
#test button.vu { display: block }
#test.vu button.vu { background: #6CF }
</style>
<form action="#" onsubmit="return false">
<p>
<span id="test" style="display:block;float:left;">
<button class="vu" onclick="blurMenu(this)">100 000</button>
<button onclick="blurMenu(this)">200 000</button>
<button onclick="blurMenu(this)">300 000</button>
<button onclick="blurMenu(this)">400 000</button>
<button onclick="blurMenu(this)">500 000</button>
<button onclick="blurMenu(this)">600 000</button>
<button onclick="blurMenu(this)">700 000</button>
</span>
<input name="myIndex" onchange="clickMenu(this.value)">
</form>


Certainly google can find you more efficients examples

one among some of them
<http://www.marghoobsuleman.com/jquery-image-dropdown>

--
sm