复选框判断问题
有10个复选框,如果name都一样,提交表单时,如何判断用户选择了哪几个复选框
------解决方案--------------------用脚本来实现吧,循环判断checked就OK了。不难
------解决方案-------------------- <script>
function check()
{
o = document.f.getElementsByTagName( "input ");
checks = new Array();
for(c=0; c <o.length; c++)
{
if(o[c].type== "checkbox " && o[c].checked) checks[checks.length]=o[c].value;
}
alert( "选择了: "+checks);
return false;
}
</script>
<form name= "f " onsubmit= "return check() ">
<input type= "checkbox " name= "c " value= "1 "> 1
<input type= "checkbox " name= "c " value= "2 "> 2
<input type= "checkbox " name= "c " value= "3 "> 3
<input type= "checkbox " name= "c " value= "4 "> 4
<input type= "checkbox " name= "c " value= "5 "> 5
<input type= "checkbox " name= "c " value= "6 "> 6
<input type= "checkbox " name= "c " value= "7 "> 7
<input type= "checkbox " name= "c " value= "8 "> 8
<input type= "checkbox " name= "c " value= "9 "> 9
<input type= "checkbox " name= "c " value= "10 "> 10
<input type= "submit ">
</form>
------解决方案--------------------那要看你得到的字符串中有哪些值
例如:
<input type= "checkbox " name= "a " value= "1 " /> checked
<input type= "checkbox " name= "a " value= "2 " />
<input type= "checkbox " name= "a " value= "3 " />
<input type= "checkbox " name= "a " value= "4 " /> checked
dim a:a=request( "a ") 'the value is 1,4
那么就是说,你选中了value= "1 " and value= "4 "的两个复选框
------解决方案--------------------嗯,只要request( "checkboxname ")一次就行了~``将获得所有选中的值,并用,分隔~
------解决方案--------------------服务器端,request.form( "a ")直接就是 value,看倒数第三楼glvicky说的
客户端JavaScript才用 *.*.value().
------解决方案--------------------可以将所选的值用“;”分隔开然后在服务器端进行split就行了