duanfazhun0383 2009-06-30 12:47
浏览 231
已采纳

选择多个选项

banging my head against the wall for something seemingly dead simple.

Here it is:

<html>
    <head></head>
    <body>
        <form method="post" action="action.php">
            <div><input type="checkbox" name="test" value="Newspaper"> <span >Newspaper</span></div>
            <div><input type="checkbox" name="test" value="PC"> <span >PC</span></div>
            <div><input type="checkbox" name="test" value="Home"> <span >Home</span></div>
            <div><input type="checkbox" name="test" value="Dont_know"> <span >dnunno</span></div>
            <input type="submit" name="Submit" value="send">
        </form>
    </body>
</html>

But when I select more then one option. I see in my print_r($_POST); statement only the last selected option in stead of all selected options. How should I deal with this?

update: I checked the rest of my code and i saw that this is done by some JavaScript.

else if (aform.validatorArr[i][4] == "checkbox") {
    var fvs = "";
    eval("var chkbArray=aform." + aform.validatorArr[i][1] + ";");
    if (aform.validatorArr[i][2] == "cb_true") {
        for (k = 0; k < chkbArray.length; k++) {
            if (chkbArray[k].checked) {
                fvs += chkbArray[k].value;
                console.log(fvs);
            }
        }
        if (fvs == false) {
            s += aform.validatorArr[i][3] + "
";
        }
    }
}

That's why the [] is not added in my html. But how could I modify this code so that it will take all options?

  • 写回答

1条回答 默认 最新

  • douji6199 2009-06-30 12:49
    关注

    Put [] after the name:

    <input type="checkbox"  name="test[]" value="Newspaper">
    

    See PHP FAQ for more details.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?