views:

836

answers:

2

I just noticed a strange behaviour in IE7.

I have radio buttons with associated labels as follows:

<input type="radio" name="filter" id="filter_1" value="Activities" checked="checked" />
<label for="filter_1">Activities</label>

<input type="radio" name="filter" id="filter_2" value="Services" />
<label for="filter_2">Services</label>

The radio button is hidden via css with display:none or visibility: hidden (don't ask)

The problem is - when I click the label in IE7 (haven't looked at other IE versions yet) the associated radio button is not actually checked. I confirmed this with jquery - the label click event is fired, but the radio button click event is not. A form post also confirms that the checked radio button does not change.

This works correctly in firefox, and also works correctly if I remove the CSS that hides the radio buttons.

Is this an IE bug or am I missing something?

+3  A: 

It probably is to do with the display: none - you may also find that hidden elements don't get their values submitted with the rest of the form. If you have control over it, you may want to try positioning the elements off screen rather then hiding them.

robertc
+1 Yes, that will work. I'm more curious if this is a known bug in IE.
ScottE
I don't think it's a known bug, so much as behaviour which is not clearly defined in the spec. Looking at the MSDN article which is linked to from the post I linked to above, it seems that this behaviour is entirely intentional on the part of IE. If something is display:none then it's effectively not part of the document. MS have chosen to therefore ignore these elements, Mozilla have chosen not to, it's not like there's a clearly right or wrong way to do it.
robertc
It's not very cool when a designer's CSS can break the data coming into a developer's form handler by failing to pass along a piece of data. This behavior smells wrong. Thanks for the workaround!
Koobz
A: 

An other similar case: if the label contains an image, clicking on the image will not check the input radio under Internet Explorer.

Toto