[Javascript] How can I make document.FormName.level.selectedIndexwork in IE?

Paul Novitski paul at juniperwebcraft.com
Mon Apr 17 22:15:10 CDT 2006


At 07:00 PM 4/17/2006, Dong, Roland wrote:
>I realize this portion of the code is not working in IE but works in
>Firefox:
><option value="1" onMouseDown="goAlert(1)">Level 1</option>
>
>I want the click on the option to trigger goAlert(). Any workaround?
>
>See testing code here:
>
>http://www.wiu.edu/users/muamw1/formtest.html


Roland, in my quick test it appears that you have to assign the 
behavior to the SELECT element, not the OPTION, in order for IE to cooperate.

Onmousedown doesn't seem appropriate because of the way we use select 
lists with the mouse, but onchange does work, and it accommodates 
keyboard usage as well:

<select name="level" id="level" size="1" 
onchange="goAlert(this.options[level.selectedIndex].value);">
         <option value="">Select</option>
         <option value="1">Level 1</option>
         <option value="2">Level 2</option>
         <option value="3">Level 3</option>
         ...

Paul 




More information about the Javascript mailing list