On the scope of radio buttons in HTML
Asked Answered
M

2

6

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.

Malm answered 9/4, 2011 at 14:8 Comment(3)
Check this fiddle. Guess it's #1. Also take note that frames have an entirely new context, this means scope doesn't pass!Propylaeum
I'd rather use ajax as progressive enhancement and not as sole solution. If one browses your site with JS disabled (smartphones!), one wouldn't be able to use your site.Hercegovina
@Hercegovina - with my previous projects agreed with you. current project only ajax etc - the application only has one initial load, everything is dynamic at that pointMalm
F
10

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/

Flare answered 9/4, 2011 at 14:14 Comment(0)
M
3

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.

Mcfall answered 9/4, 2011 at 14:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.