I knew radio buttons allow for a single selection,
but mine allows multiple button selection.
please i need a solution.
thanks.

Dani AI

Generated

your radios allow multiple selections because each input has a different name. Browsers group radios by identical name within the same form, not by table cells. So three different names creates three separate one-choice groups. and pointed you the right way; @diafol was spot on about showing code. Also note: tabindex and <td> placement do not affect grouping.

Here is a clean, accessible pattern. All three radios share the same name and have unique ids; only one uses checked.

<form action="process.php" method="post">
  <fieldset>
    <legend>Role</legend>

    <label for="role-student">
      <input type="radio" id="role-student" name="role" value="student" checked>
      Student
    </label>

    <label for="role-teacher">
      <input type="radio" id="role-teacher" name="role" value="teacher">
      Teacher
    </label>

    <label for="role-other">
      <input type="radio" id="role-other" name="role" value="other">
      Other
    </label>
  </fieldset>
</form>

On the PHP side, you will receive a single value under $_POST['role']. Validate it and handle unexpected input:

$role = $_POST['role'] ?? null;

$allowed = ['student', 'teacher', 'other'];
if (!in_array($role, $allowed, true)) {
    // invalid or missing selection; handle gracefully
    // e.g., show an error or set a safe default
}

Tip: if you need two independent single-choice groups (e.g., Role and Shift), give each group its own shared name (role, shift). If you truly need multiple selections, use checkboxes instead of radios.

Recommended Answers

All 7 Replies

Have you specified that they are in a group, they only allow for single selection if they are part of a group.

For example

<input type="radio" name="group1" value="PersonA">
<input type="radio" name="group1" value="PersonB">
<input type="radio" name="group1" value="PersonC">

OK.
They are on different <td> tags but can't i please allow just a single selection?

<td> tags are for tables not for the selection of radio buttons. to group radio buttons together, the names of all the radio buttons should be the same, like in the example I have shown you above.

Member Avatar for Member #120589

It would help if you showed your code. How do you expect somebody to help when they can't see your problem?

<tr><td>
student<input name="student" type="radio" value="student" checked tabindex="1"/>
teacher<input name="teacher" type="radio" value="teacher" tabindex="2"/>
other  <input name="other" type="radio" value="other" tabindex="3"/> 
<br/>
<img src="images/student.png" alt="student" width="50px" height="40px">
<img src="images/teacher.png" alt="teacher" width="50px" height="40px">
<img src="images/other staff.png" alt="other" width="50px" height="40px">
</td></tr>

mikulucky already give you the answer.

wow, just got the answer.
The inputs should have the same 'name' value.
thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.