Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can I check multiple radio buttons?

I have a HTML form with radio buttons and are able to select multiple but why? I can't help myself.

This is my HTML:

<input type="radio" name="nameA" id="nameA" value="nameA">
<label for="nameA">Choice A</label>
<input type="radio" name="nameB" id="nameB" value="nameB">
<label for="nameB">Choice B</label>

For anyone finding this question: Solution is to give them the same NAME

<input type="radio" name="sameName" id="nameA" value="nameA">
<label for="nameA">Choice A</label>
<input type="radio" name="sameName" id="nameB" value="nameB">
<label for="nameB">Choice B</label>
like image 579
t3ax Avatar asked Apr 12 '18 13:04

t3ax


People also ask

Why can I select multiple radio buttons?

Only one radio button in a group can be checked. You have two radio buttons with different names. This means that you have two radio groups, each containing one radio button. You need to put them in the same group (by making them share a name) if you only want one of them to be selected.

How can I set only one radio button checked?

Radio buttons are normally presented in radio groups (a collection of radio buttons describing a set of related options). Only one radio button in a group can be selected at the same time. Note: The radio group must have share the same name (the value of the name attribute) to be treated as a group.

Can we select multiple radio buttons Android?

To create each radio button option, create a RadioButton in your layout. However, because radio buttons are mutually exclusive, you must group them together inside a RadioGroup . By grouping them together, the system ensures that only one radio button can be selected at a time.

How do I enable multiple selected radio buttons in HTML?

Check boxes allow multiple selections at a time and radio buttons allow only a single selection at a time, but both use the <input> tag to create each box or button.

When to use radio buttons or checkboxes?

Classics like that you should use radio buttons (single select) or checkboxes (multiple select) if you’re showing five or fewer options, and the different options when the number of options grows from there. One thing that isn’t talked about is how you implement these things.

How to select multiple radio buttons at the same time?

Radio buttons are normally presented in radio groups. Only one radio button in a group can be selected at the same time. The radio group must share the same name (the value of the name attribute) to be treated as a group. Selecting any radio button in that group automatically deselects any other selected radio button in the same group. Good...

How are radio buttons presented in a group?

Radio buttons are normally presented in radio groups. Only one radio button in a group can be selected at the same time. The radio group must share the same name (the value of the name attribute) to be treated as a group.

What happens when you press a radio button?

Each radio button has a name and a value. If they are in the same FORM and have the same name they are connected. Pressing one will clear all others with the same name and the value for that button will be what the form reports to the server. How do I change the size of radio buttons?


1 Answers

All radio buttons that share the same name and are controls in the same form are part of a group.

Only one radio button in a group can be checked.

You have two radio buttons with different names. This means that you have two radio groups, each containing one radio button.

You need to put them in the same group (by making them share a name) if you only want one of them to be selected.

(They should still have unique ids (so you can give each one a label) and values (which is how you determine which one was checked when the form is submitted to the server)).

<form>
  <fieldset>
    <legend>Thing that is being chosen</legend>

    <input type="radio" name="name" id="nameA" value="nameA">
    <label for="nameA">Choice A</label>

    <input type="radio" name="name" id="nameB" value="nameB">
    <label for="nameB">Choice B</label>

  </fieldset>
</form>
like image 51
Quentin Avatar answered Oct 17 '22 10:10

Quentin