Richard JP Le Guen
Richard JP Le Guen

Reputation: 28753

Radio Buttons with different Names?

Does anyone have a no JavaScript way to make HTML radio buttons belonging to the same "group" have different "name" attributes?

While I figure there isn't any way, I'm working on a site which needs to still be function when JS is off, and this would be ideal.

Addendum

It's not a requirement as much as a preference; there's a kind of consistency in the solution I'm trying to respect about the format and naming of parameters which get POSTed. Of course, if need be, I'll ditch it, but if I can make it work I'll get that warm fuzzy feeling...

Upvotes: 4

Views: 7628

Answers (2)

matt
matt

Reputation: 11

Just came across this then solved it for my functionality, I know it's an old thread but as I would have found this info useful 20 minutes ago here's what I did:

keep them grouped with the same name attribute, but differentiate between them after they have been submitted by checking their value in post array. i.e.

`

// first radio button
if ($_POST['someValue'] == 'someString') {

  // do something

// second radio button
} elseif ($_POST['someValue'] == 'anotherString') {

  // do something else

}

`

hope that's useful to someone in the future

Upvotes: 1

Chris Schmich
Chris Schmich

Reputation: 29466

According to the HTML 4.01 spec, the name defines the group, so no, I don't think there'll be a non-JavaScript way to do this.

What are you trying to achieve such that you need radio buttons with different name attributes to be considered as part of the same group? Can you use the id or class attributes to differentiate them for whatever you're trying to do?

Upvotes: 5

Related Questions