tibbe
tibbe

Reputation: 9009

Does setting the checked attribute on a radio button change the checked attributed on other buttons with the same name?

If I have a group of radion buttons, with one being set as checked by default:

<input type="radio" id="id1" name="grp" value="val1" checked="checked">
<input type="radio" id="id2" name="grp" value="val2">
<input type="radio" id="id3" name="grp" value="val3">

If I now get the element with ID "id2" and do

var el = ...;
el.checked = true;

will the checked property for the other elements automatically be set to false?

Bonus points for a link to official documentation describing the behavior.

Upvotes: 1

Views: 596

Answers (1)

T.J. Crowder
T.J. Crowder

Reputation: 1074979

Does setting the checked attribute on a radio button change the checked attributed on other buttons with the same name?

Yes, it does. I'm surprised to find that this behavior isn't clearly documented in the DOM2 HTML specification. It is, though, documented in the HTML5 specification and the HTML 4.01 specification.

Gratuitous live example

Upvotes: 2

Related Questions