Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

On the scope of radio buttons in HTML

Several radio buttons with the same name act as a set, where checking one unchecks the others. What is the scope of this behavior?

  1. The form in which the button resides
  2. The page / document on which the button resides
  3. Does scope pass into iframes?

I have always used them in forms, but now writing formless HTML (using ajax for posting), and everything seems to be working just fine, so my guess is #2.

like image 535
cc young Avatar asked Apr 09 '11 14:04

cc young


2 Answers

Radio buttons with the same name in the same form act as a set, but not with those of different forms. Radio buttons with no form act as a set with those with no forms.

test it yourself: http://jsfiddle.net/8qqNC/1/

like image 119
tcooc Avatar answered Sep 28 '22 00:09

tcooc


Radio buttons are scoped to the form they are in.

Frames contain external documents, and nothing in them is considered part of the current document, let alone an element within that document.

like image 42
Quentin Avatar answered Sep 27 '22 23:09

Quentin