Radio Buttons and Name Attributes


Why all related radio buttons should have the same name attribute???


Radio buttons are grouped in a way that you should only be able to select one button from a group. You don’t want people to select ‘boy’, ‘girl’, AND ‘complicated’ from a gender field (… which is a terrible thing to ask anyway in today’s world. Only hospitals and the like actually NEED to know gender).

The name attribute is how the browser knows that these radio buttons are related. Different groups of radio buttons can have different names so they don’t interfere with each other. Without name, your “preferred in-flight meal” group could interfere with your “gender” group.

Also, radio buttons don’t toggle; you can’t turn the off after you turn them on (for that, you should be using a checkbox instead). In order to turn one radio button in a group off, you need to turn another on.


That makes more sense.