[thelist] NS6 radio buttons bug

Erika Chang ecreg at redhotchips.demon.co.uk
Thu Mar 29 06:18:14 CST 2001


>IE also has some radio/checkbox quirks. Try this:
>
><form>
><input type="checkbox" name="val" onClick="alert(this.value)"> Value 1
></form>
>
><form>
><input type="radio" name="val" value="Value 1" onChange="alert(this.value)"> Value 1<br>
><input type="radio" name="val" value="Value 2" onChange="alert(this.value)"> Value 2<br>
><input type="radio" name="val" value="Value 3" onChange="alert(this.value)"> Value 3
></form>
>
>The checkbox always returns 'on'

Seem to happen with IE4+, NS4 when you don't specify a value for the checkbox. Acutally, withe NS6, if your submit the form, you'd see that the default value is also "on". Probably a way to make sure when the form is submitted, there is some way to check that the checkbox is checked.

Better off specifying a value for checkboxes anyway.

> and the radio buttons react even stranger.
>
>According to HTML 4 (http://www.w3.org/TR/html4/interact/scripts.html):
>
>onclick "may be used with most elements".
>
>onchange "applies to the following elements: INPUT, SELECT, and TEXTAREA"

But according to O'Reilly's JS book, radio & checkbox don't do onchange, only onclick, that only text input elements & select respond to onchange.

If you read that spec more carefully, it says

"The onchange event occurs when a control loses the input focus and its value has been modified since gaining focus."

so depending on how the browsers implement radio & checkboxes, you might not get that event occuring.

Tested NS4, behave as described in the book. NS6 seems to respond as soon as you click & change the checked status. IE seems to interpret the spec faithfully/literally and only alert when the radio or checkbox loses focus -- ie when you click on a second item or when you click outside the current item.




More information about the thelist mailing list