...

View Full Version : onClick Working in FF, but not IE



kraftomatic
07-06-2006, 01:58 AM
Hey Guys,

I'm having a problem with the following form option:


<select name="group" class="textbox">
<option value="1">1</option>
<option value="2">2</option>
<option value="3" onClick="alert('hello world')">3</option>
</select>

It works in Firefox, but doesn't work in IE. What am I doing wrong here? I need a particular function to be called when a specific option is selected within a SELECT, and in IE, it does nothing.

Any suggestions would be greatly appreciated.

Thanks!

_Aerospace_Eng_
07-06-2006, 02:03 AM
Options can't have event handlers. You need to use onchange in the select with a combination of an if statement

<select name="group" class="textbox" onchange="if(this.options[this.options.selectedIndex].value == '3') alert('hello world')">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>

Mongus
07-06-2006, 02:03 AM
Will this work?
<script type="text/javascript">
function groupChanged(select)
{
switch(select.options[select.selectedIndex].value)
{
case '3':
alert('hello world');
break;
}
}
</script>

<select name="group" class="textbox" onchange="groupChanged(this)">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>

kraftomatic
07-06-2006, 02:08 AM
Thanks guys. Aero's worked and did what I need it to do.

Thanks again.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum