douyi3760 2015-01-11 21:13
浏览 48
已采纳

Checkbox保持返回true

I have a terms box on my register page, and I am sending that value to a php page where I check the value with the code;

'&terms=' + $("#terms").attr('checked')

and this is the html checkbox:

<input type="checkbox" name="terms" id="terms" data-validate="required"  /> 

In my php, I have tried multiple things, if it's set, if the value is equal to 1 and if it's empty yet my PHP code doesn't run, here's my PHP code:

        $termscheck = isset($_POST['terms']) ? '1' : '';
        if (!$termscheck == 1)
        {
            echo '
                  <div class="col-md-5">
                  <div class="alert alert-danger">
                  <strong>Oh snap!</strong>Must accept terms of service
                  </div>
                  </div>';
            die;
        }

Even when the terms checkbox is and isn't checked that code never runs for some reason. How come?

  • 写回答

2条回答 默认 最新

  • dpx86402 2015-01-11 21:16
    关注

    Use $('#terms').is(':checked') instead of attr

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源