关于checkbox的问题!

pantao2003 2004-04-10 01:55:09
我的配置:win2003+IIS6.0+php4.22
aaa.php
<html>
<head>
<script language="javascript">
<!--
function check_select()
{
var blo_flag=false;
for(int_i=0;int_i<document.form1.ch.length;int_i++)
{
if(document.form1.ch[int_i].checked)
blo_flag=true;
}
if(!blo_flag)
{
alert("你至少要选取一个题目");
return false;
}
return true;
}
//-->
</head>
...
<form name="form1" action="bbb.php" method="post" onSubmit="return check_select()">
<input name="ch[]" type="checkbox" value="1">1
<input name="ch[]" type="checkbox" value="2">2
<input name="ch[]" type="checkbox" value="3">3
<input name="submit" type="submit" value="yes">
</form>

bbb.php
...
$arr_id=$_POST['ch'];
...

我的想法就是用户在aaa.php中至少要点选一个checkbox,而我又不能设置一个初始值.然后在bbb.php中
得到用户点选的checkbox的值.
可是问题是在aaa.php中,如果用户一个都不选的话,javascript的函数check_select()并不能实现检查.
我如果把<input name="ch[]" 改为name="ch"的话,那么可以实现检查.可是在bbb.php中我就得不到正确
的结果了,$arr_id只有一个值而不管用户点选几个checkbox.真是顾得了头顾不了尾呀!我该怎么办!
请帮帮忙,多谢了!





...全文
50 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
pantao2003 2004-04-10
  • 打赏
  • 举报
回复
好的,我马上试一下,多谢先哟!
amethyst99 2004-04-10
  • 打赏
  • 举报
回复
只需要对js的写法做一些小的改动
amethyst99 2004-04-10
  • 打赏
  • 举报
回复
<script language="javascript">
<!--
function check_select()
{
var blo_flag=false;
for(int_i=0;int_i<document.form1["ch[]"].length;int_i++)
{
if(document.form1["ch[]"][int_i].checked)
blo_flag=true;
}
if(!blo_flag)
{
alert("你至少要选取一个题目");
return false;
}
return true;
}
//-->
</script>

21,887

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧