Udit Gupta
Udit Gupta

Reputation: 3272

why radio button is not behaving properly ??

This is short part of my code which display radio buttons.

<table width="100%">
    <tr>

    <td style="text-align:center">
    <input type="radio" name="ah" value="" id="ah" align="left" checked="checked" />AH
    </td>

    <td style="text-align:center">
    <input type="radio" name="esp" value="none" id="esp" align="right"/>ESP
    </td>

    </tr>
</table>

The problem is that the one radio button (AH) is by default checked as mentioned here and when i click on other radio button it also gets checked but now both are checked how would I disable them. I think it should happen automatically when I click on one radio button other button should be disabled automatically. please correct me where am I wrong???

Upvotes: 0

Views: 276

Answers (4)

Joseph Silber
Joseph Silber

Reputation: 219920

To group radio buttons together, they should share the same name:

<table width="100%">
    <tr>

    <td style="text-align:center">
    <input type="radio" name="someName" value="AH" id="ah" align="left" checked="checked" />AH
    </td>

    <td style="text-align:center">
    <input type="radio" name="someName" value="ESP" id="esp" align="right"/>ESP
    </td>

    </tr>
</table>

Upvotes: 6

haseebkhan
haseebkhan

Reputation: 35

try this it will help.... you have to give the same name to both radio button

<table width="100%">
    <tr>

    <td style="text-align:center">
    <input type="radio" name="esp" value="" id="ah" align="left" checked="checked" />AH
    </td>

    <td style="text-align:center">
    <input type="radio" name="esp" value="none" id="esp" align="right"/>ESP
    </td>

    </tr>
</table>

Upvotes: 1

aziz punjani
aziz punjani

Reputation: 25766

They need to have the same name attribute.

Upvotes: 1

Pekka
Pekka

Reputation: 449385

You need to give both radio buttons the same name attribute so the browser can recognize them as being in the same group.

Upvotes: 2

Related Questions