Home > Software engineering >  Is there a way to have exclusive radio inputs within a table?
Is there a way to have exclusive radio inputs within a table?

Time:09-10

I am trying to make a questionare table. However, the radio inputs arn't exclusive when selecting (I am able to select both and unable to deselect)

        <fieldset>
            <legend>test form</legend>
            <table>
                <tr>
                    <th></th>
                    <th>Yes</th>
                    <th>No</th>
                </tr>
                <tr>
                    <th>test question?</th>
                    <form>
                    <td><input id="yes1" type="radio"></td>
                    <td><input id="no1" type="radio"></td>
                    </form>
                </tr>
            </table>
        </fieldset>

Is there a fix to this and, if so, how do I fix it?

I expected that since I put the td elements nested in the form element it would solve the problem. But it never did.

CodePudding user response:

The problem is that you need them to share that same 'name' attribute so HTML will know that they are connected

<td><input id="yes1" name="1" type="radio"></td>
<td><input id="no1" name="1" type="radio"></td>
  • Related