douji6199 2018-07-27 09:53 采纳率: 100%
浏览 85

我有多个与数组相同名称的单选按钮和相同的值[重复]

i have multiple radio button in same name as array and same value for all.

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

in php i used like this

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

im getting result like this :

Array ( [0] => 1 )

if i uncheck the button set as zero i want result to be like this

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

Please check this images i have form like this

</div>
  • 写回答

3条回答 默认 最新

  • dongqian0763 2018-07-27 09:55
    关注

    You need to use only [] instead of array keys also use checkbox instead of radio . So use following code it will work for you.

             <input type="checkbox" name="radio_name[]" id="radi_name1" value="1" checked>
             <label for="radio1">Set as Default</label>
             <input type="checkbox" name="radio_name[]" id="radi_name2" value="1"  >
             <label for="radio1">Set as Default</label>
             <input type="checkbox" name="radio_name[]" id="radi_name3" value="1"  >
             <label for="radio1">Set as Default</label>
             <input type="checkbox" name="radio_name[]" id="radi_name4" value="1" >
             <label for="radio1">Set as Default</label>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题