注册 登录
编程论坛 ASP技术论坛

路的方向

yql100059 发布于 2010-06-13 17:13, 437 次点击
<html>
<head><title></title>
<script language="vbscript">
<!--
sub checkvl()
dim e
e=bb.e.value
if e=""then
msgbox"........",0+48
focusto(0)
exit sub
else
document.bb.submit()
end if
end sub
sub focusto(x)
document.bb.elements(x).focusto()
end sub
-->
</script>
</head>
<body>
<form method="post" action="a.asp"name="bb">
<input name="e" type="checkbox"value="c">c
<input name="e" type="checkbox"value=d">d
<input name="e" type="checkbox"value="f">f
<input type="button" name="but1"value="提交" onclick="checkvl()">
<input type="reset"name="but2"value="取消">
</body>
</html>
小弟初来驾到,才学ASP,上面有个表单,想在点击提交按扭时对表单的内容进行验证,对复选框的验证,在多个选项中必须最少选择一个,必须对复选框进行选择。小弟先在这谢谢大家!~~   请用VB脚本
4 回复
#2
icecool2010-06-14 01:17


<html>
<head><title></title>
<script language="javascript">
<!--
function checkvl()
{
   var tem=0;
   for(var i=0;i<3;i++)
   {
       if(document.bb.e[i].checked)
          {
          tem=tem+1;

          }
   }
   if(tem<1){
            alert("至少选择一项!");
            return false;

             }
            document.bb.submit();
}
</script>
</head>
<body>
<form method="post" action="a.asp" name="bb">
<input name="e" type="checkbox" value="c">c
<input name="e" type="checkbox" value="d">d
<input name="e" type="checkbox" value="f">f
<input type="button" name="but1" value="提交" onclick="checkvl();">
<input type="reset" name="but2" value="取消">
</form>
</body>
</html>

不好意思,没看到要用VBS...

[ 本帖最后由 icecool 于 2010-6-14 09:05 编辑 ]
#3
icecool2010-06-14 08:56
<script language="vbscript">
function checkvl()
tem=0
for i=0 to 2
     if document.forms("bb").e(i).checked then
        tem=tem+1
     end if
next
     if tem<1 then
        msgbox "至少选择一项"
        exit function
     else
        document.bb.submit()
     end if
end function
</script>

<html>
<head><title></title>
</head>
<body>
<form method="post" action="a.asp" name="bb">
<input name="e" type="checkbox" value="c">c
<input name="e" type="checkbox" value="d">d
<input name="e" type="checkbox" value="f">f
<input type="button" name="but1" value="提交" onclick="checkvl()" >
<input type="reset" name="but2" value="取消">
</form>
</body>
</html>

[ 本帖最后由 icecool 于 2010-6-14 13:46 编辑 ]
#4
yql1000592010-06-14 11:34
谢谢你呀!大哥 !~~~你设计的语句我看了,也能运行的起。也大概明白了你没个语句所表达的意思!你能不能看出我刚刚上面的那个语句在运行的时候是那里出错,获取不到VALUE值。
#5
icecool2010-06-14 12:40
value的值这样可以获得:document.forms("bb").e(i).value

你那语句因逻辑上有问题,不管你选中没有,VALUE的值都是存的不可能为空。
1