简体   繁体   English

我在数组中有多个具有相同名称的单选按钮,并且具有与1相同的值

[英]I have Multiple radio button with same name in it of array and have same values as 1

I have multiple radio button name in array with same values as 1 for all. 我在数组中有多个单选按钮名称,所有名称均具有相同的值。 I need want to get if uncheck means set as zero how can I do that. 我需要获取是否将uncheck表示设置为零,我该怎么做。 Below is my code 下面是我的代码

check image its sample image but same form like i having : 检查图像的样本图像,但是像我一样的形式

html code : html代码

<input type="radio" name="radio_name[]" id="radi_name" value="1" checked >
<label for="radio1">Set as Default</label>

PHP code : PHP代码

$a[]=$_post['radio_name'];
prinr_r($a);

Current result : 当前结果

Array ( [0] => 1 )

Expected result : 预期结果

Array ( [0] => 1,[1] => 0,[2] => 0,[3] => 0 )

I have checked one radio button only, rest all need to zero. 我只检查了一个单选按钮,其余所有都需要清零。

use it like. 用起来像。

    <form method='post' id='userform' action='test2.php'> <tr>
        <td>Trouble Type</td>
        <td>
        <input type='checkbox' name='checkboxvar[]' class="check" value='1'>1<br>
        <input type='checkbox' name='checkboxvar[]' class="check"  value='1'>2<br>
        <input type='checkbox' name='checkboxvar[]'  class="check"  value='1'>3
        </td> </tr> </table> <input type='button' class='buttons'> </form>

<script type="text/javascript">
        $(document).ready(function(){
            $('.buttons').click(function(){
                var checkbox_arr = [];
                $('.check').each(function(){
                    checkbox_arr.push(+$(this).is( ':checked' ));
                });
                console.log(checkbox_arr);
            });
        });
    </script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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