简体   繁体   中英

Associating radio buttons to individual groups

I have several rows in a table. Each row has two radio buttons which should be only associated with each other, but not be associated with the radio buttons in the other rows. When submitted, my desire is to have given the below a three element array for pk1 , pk2 , and options . The following will not work as all the options radio buttons are associated, and thus only one can be selected, and not one per row be selected as I desire. How can I make the radio buttons only be associated on a per row basis.

<table>
    <tr>
        <td>1<input type="hidden" name="pk1[]" value="1"></td>
        <td>1<input type="hidden" name="pk2[]" value="1"></td>
        <td>1<input type="hidden" name="pk3[]" value="1"></td>
        <td>option1 <input type="radio" name="option[]" value="yes"></td>
        <td>option2 <input type="radio" name="option[]" value="no"></td>
    </tr>
    <tr>
        <td>5<input type="hidden" name="pk1[]" value="5"></td>
        <td>3<input type="hidden" name="pk2[]" value="3"></td>
        <td>1<input type="hidden" name="pk3[]" value="1"></td>
        <td>option1 <input type="radio" name="option[]" value="yes"></td>
        <td>option2 <input type="radio" name="option[]" value="no"></td>
    </tr>
    <tr>
        <td>1<input type="hidden" name="pk1[]" value="1"></td>
        <td>1<input type="hidden" name="pk2[]" value="1"></td>
        <td>2<input type="hidden" name="pk3[]" value="2"></td>
        <td>option1 <input type="radio" name="option[]" value="yes"></td>
        <td>option2 <input type="radio" name="option[]" value="no"></td>
    </tr>
</table>

Add an explicit index to the button names.

<table>
    <tr>
        <td>1<input type="hidden" name="pk1[]" value="1"></td>
        <td>1<input type="hidden" name="pk2[]" value="1"></td>
        <td>1<input type="hidden" name="pk3[]" value="1"></td>
        <td>option1 <input type="radio" name="option[0]" value="yes"></td>
        <td>option2 <input type="radio" name="option[0]" value="no"></td>
    </tr>
    <tr>
        <td>5<input type="hidden" name="pk1[]" value="5"></td>
        <td>3<input type="hidden" name="pk2[]" value="3"></td>
        <td>1<input type="hidden" name="pk3[]" value="1"></td>
        <td>option1 <input type="radio" name="option[1]" value="yes"></td>
        <td>option2 <input type="radio" name="option[1]" value="no"></td>
    </tr>
    <tr>
        <td>1<input type="hidden" name="pk1[]" value="1"></td>
        <td>1<input type="hidden" name="pk2[]" value="1"></td>
        <td>2<input type="hidden" name="pk3[]" value="2"></td>
        <td>option1 <input type="radio" name="option[2]" value="yes"></td>
        <td>option2 <input type="radio" name="option[2]" value="no"></td>
    </tr>
</table>

For consistency, you might want to add them as well to the hidden inputs, although they'll get the same indexes automatically.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM