Page 1 of 1

Disabling Select Box Options in Explorer (not whole select)

Posted: Thu Nov 25, 2004 11:16 am
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.

Posted: Thu Dec 09, 2004 6:56 am
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...

Posted: Mon Dec 13, 2004 5:35 am
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...