Why can I check more than 1 radio buttons in this code

<body>
    <form name="search_form" id="search_form" method="POST" action="search_user_data.php">
        <table border="1">
            <tr>
                <td colspan="2">
                    <input type="text" id="search" name="search" />
                </td>
                <td>
                    <input type="submit" value="Search"/>
                </td>
            </tr>
            <tr>
                <td>
                    <input type="radio" name="id_radio"/>ID
                </td>
                <td>
                    <input type="radio" name="surname_radio"/>Surname
                </td>
                <td>
                    <input type="radio" name="dob_radio"/>DoB
                </td>
            </tr>
        </table>
    </form>
</body>
+3
source share
5 answers

Because the attribute namein the switch must be the same in the radio group.

Try the following:

<input type="radio" name="somename" value="id_radio"/>ID
<input type="radio" name="somename" value="surname_radio"/>Surname
<input type="radio" name="somename" value="dob_radio"/>DoB

Additional information on w3c

+15
source

An attribute nameis what links the radio buttons in a group. Use valuefor the actual value of each button.

            <td>
                <input type="radio" value="id_radio" name="btn_group"/>ID
            </td>
            <td>
                <input type="radio" value="surname_radio" name="btn_group"/>Surname
            </td>
            <td>
                <input type="radio" value="dob_radio" name="btn_group"/>DoB
            </td>
0
source

, . 1 , :

<input type="radio" name="radioGroup" value='id'/>ID
<input type="radio" name="radioGroup" value='surname'/>Surname
<input type="radio" name="radioGroup" value='dob'/>DoB

http://www.echoecho.com/htmlforms10.htm

0

.

0

Your problem is that you have different names for each switch so that they are grouped together, they should have the same name, it looks like you are confusing the name and value.

<body>
    <form name="search_form" id="search_form" method="POST" action="search_user_data.php">
        <table border="1">
            <tr>
                <td colspan="2">
                    <input type="text" id="search" name="search" />
                </td>
                <td>
                    <input type="submit" value="Search"/>
                </td>
            </tr>
            <tr>
                <td>
                    <input type="radio" name="searchType" value="id_radio"/>ID
                </td>
                <td>
                    <input type="radio" name="searchType" value="surname_radio"/>Surname
                </td>
                <td>
                    <input type="radio" name="searchType" value="dob_radio"/>DoB
                </td>
            </tr>
        </table>
    </form>
</body>
0
source

All Articles