Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create mutually exclusive radio buttons with different names?

Tags:

I have a few radio buttons that belong to the same category, but I want to name them differently and make them mutually exclusive. How do I do that? Based on the selected value, I do different actions, and I can't access them if they have the same name.

like image 364
yogsma Avatar asked Jul 09 '10 20:07

yogsma


People also ask

Can radio buttons have different names?

Each check box must have a unique name. Radio buttons allow only one choice within a group of buttons. Each radio button within a group should have the same name. You can create more than one group of radio buttons by using different names.

Are radio buttons mutually exclusive?

Radio buttons are mutually exclusive. Click on either, and the other(s) will be unselected. The black dot in the middle of a radio button indicates it is selected.

Can radio buttons have multiple selections?

Radio buttons allow a user to select a single option among multiple options. You can set the Choice Value of each option, for each button, as well as group these buttons by giving them the same Group Name.

Can radio button have two values?

Not as such. You could use a serialisation technique to store a more complex data structure as a string (for example: JSON) and then decode it on the server. Show activity on this post. in javascript: First of all, get the value, then split it by a comma and make it like an arry.


1 Answers

Why can't you access them if they have the same name? You can add IDs (you should), you can distinguish by value or just count them and use the n-th element.

You should give radiobuttons the same name to make the browser understand they are exclusive.

You could (but should not) hack around this, and give each object a different name. Then add an onSelect/onClick handler for each object, and when the event fires, "uncheck" the other buttons. This is dirty and should be avoided.

like image 111
Konerak Avatar answered Sep 21 '22 13:09

Konerak