Disabling Select Box Options in Explorer (not whole select)

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Disabling Select Box Options in Explorer (not whole select)

Post by CoderGoblin »

Hello all,

Pulling what little hair I have out on this one unfortunately.

Is there any way to disable an individual option (preferably through javascript) within a select box when browsing with Internet Explorer.

This works in Mozilla and Firefox...

Code: Select all

<select name="Hello">
<option value=1 onclick="javascript:setFields(this);">Value1</option>
<option value=2 disabled>Value2</option>
<option value=3 style="display:none;">Value3</option>
<option value=4 style="visibility: hidden;">Value4</option>
<option value=5 style="color:blue;">Value5</option>
</select>
In Internet Explorer they are all visible with no style handling. Ideally I would like to toggle a the option to be disabled or not using javascript.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

I've tried to do a similar thing in the past. It eventually came down to just having a set of select boxes with varying options and changing innerHTML within a span accordingly. I'm not even sure it's in the W3C specs for the individual options...
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

Thanks for your response,

In the end I made a compromise and for users using Mozilla the tag gets disabled. For IE users if they select an invalid entry they get a warning message via javascript (Javascript must be enabled to use the page anyway). On form submit all the values get checked and another message is displayed. This way IE users may not have everything as "nice" as other browsers but simplified code for maintenance reasons (checks need to be performed anyway). If other browsers behave the same as IE they are caught as well.

If anyone else has any ideas feel free to post them...
Post Reply