Forum Moderators: not2easy

Message Too Old, No Replies

IE8 bug when multiple select list box is disabled

         

Fotiman

5:17 pm on Feb 11, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The following applies to Internet Explorer 8 only.

This example shows that when you disable a multiple select element (aka list box) that has selected options, the style of the entire select box and options changes such that you can't tell which items are selected. This is in contrast to all other browsers, which still identify the selected items (via background color, etc.).


<html>
<head>
<title>IE8 Disabled Multiple Select Bug</title>
</head>
<body>
<form action="#" method="get">
<select size="10" name="lstBox" multiple="multiple" disabled="disabled"
id="lstBox">
<option selected="selected" value="S1">Selected</option>
<option value="NS1">Not selected</option>
<option selected="selected" value="S2">Selected</option>
<option value="NS2">Not selected</option>
<option selected="selected" value="S3">Selected</option>
<option selected="selected" value="S4">Selected</option>
</select>
<br>
<input name="optEnabled" checked="checked" type="radio"
value="disabled"
onclick="document.getElementById('lstBox').disabled=true;"
> Disabled
<br>
<input name="optEnabled" type="radio" value="enabled"
onclick="document.getElementById('lstBox').disabled=false;"
> Enabled
</form>
</body>
</html>


Does anyone know of a work around for this?

One solution I've found requires JavaScript that walks through the selectelement.options array and sets the backgroundColor on each element in the array that has selected == true. But this seems messy to me, and requires also removing the style when the select element becomes enabled again.

Note: The readonly attribute doesn't apply to select elements (not sure why... seems like a big oversight to me). So setting that instead of disabled is not an option.

alt131

5:54 am on Feb 12, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



for a day when nothing interesting seemd to be happening ;) I simply hadn't pondered on how many display variations exist. Oddly, older versions seemed to handle things better. It is also a disaster given browser manufactuerers tend to do their own thing with form controls - supposedly as part of guaranteeing accessibility and usability. Humph!

Given my indignation about this usability disaster, I was hoping there might be a superior solution than this "fix", but until one is posted: It is possible to style some aspects of the form elements, and the following produced a display most similar to other browsers:
select[disabled="disabled"] {background-color:#D4D0C8;}
select[disabled="disabled"] option[selected="selected"] {background-color:navy;}
(More or less specific depending on what else is on the page)
But:
The styles will only be applied if there is a doctype (this validates as transitional)
Or
By forcing compatibility mode using
[size=2]<meta http-equiv="X-UA-Compatible" content="IE=8">[/size]

Fotiman

2:53 pm on Feb 12, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Awesome! I was hoping there would be a straightforward and simple solution to this. Works like a charm. Thanks.

One question. Is there a way to target IE8 only with this rule, since that seems to be the only offending browser?
Edit: Scratch that. I can target IE8 by using a Conditional Comment.