IE capture option element onclick
August 8, 2006
/ Filed under: Browsers, JavaScript
IE 6 doesn’t support this:
<select id="do">
<option onclick="do('Do This')" value="Do This"> Do This </option>
<option onclick="do('Do That')" value="Do That"> Do That </option>
</select>
This is aggravating, when you need to perform a certain function, dependent upon each option chosen from the list. For example, if someone chooses "Do This" from the select list, I need a certain function to run. However, if someone chooses "Do That" from the select list, I need a different function to run. Turns out IE only recognizes onchange. So, instead of applying an
<select id="do" onchange="do( this.value )">
<option value="Do This"> Do This </option>
<option value="Do That"> Do That </option>
</select>
The JavaScript
function do( optionValue )
{
switch( optionValue )
{
case "Do This" :
// SPECIFIC CODE HERE
break;
case "Do That" :
// SPECIFIC CODE HERE
break;
}
}
Comments/Mentions
|
Editor PicksEmail NewsletterSubscribe to the digest newsletter to receive posts by email: Recent Comments
Advertisements
|
This is a great work around for IE but it is now restricted by onchange events. If you click the same option value twice it will only respond the first time until you click another option value(hence the onchange event). Does anyone know of a way to workaround this so that every time you click the option value it will launch the event similar to how onclick works?