选择多个选项 [英] select multiple options

查看:41
本文介绍了选择多个选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的头撞在墙上,似乎很简单.

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

这里是:

<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>

但是当我选择更多选项时,一个选项.我在 print_r($ _ POST); 语句中仅看到最后一个选择的选项,而不是所有选择的选项.我该如何处理?

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?

更新:我检查了其余的代码,发现这是通过某些JavaScript完成的.

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] + "\n";
        }
    }
}

这就是为什么[]没有添加到我的html中的原因.但是,我该如何修改此代码,使其采用所有选项?

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

推荐答案

在名称后放置[]:

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

有关更多信息,请参见 PHP FAQ 详细信息.

See PHP FAQ for more details.

这篇关于选择多个选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆