Site Navigation

Sunday, September 16, 2007

bug 116 - for attribute woes in IE6

Issue: #116
Affects: IE6
Trackers:MSKB Tracker: 314279

The for attribute on a label element will give focus to the related form option, and in the case of radio/checkbox elements, it will select/unselect them. However in IE6, a label with a for attribute linked to a select list will cause a re-selection of the first option instead of just giving focus.


<label for="colorOptions">Color:</label>
<select name="color" id="colorOptions">
<option value="1">Blue</option>
<option value="2">Green</option>
<option value="3" selected="selected">Red</option>

Clicking on "Color:" should put focus on the selected value "Red" in the select box. However IE6 will give it focus, but select another option, in this case "Blue".

Known Workarounds: One. IE has a proprietary event called "onfocusin" if you attach code to this, you can reset the correct value. However most advise that you try to avoid using the label element for a select list with a pre-selected value in IE6.

Example Workaround Code:
See MSKB Article: #314279

Related Issues: None.