<HTML>
<HEAD><TITLE>简单验证</TITLE>
<SCRIPT LANGUAGE="VBScript">
<!--
Sub Submit1_OnClick
Dim TheForm
Set TheForm = Document.ValidForm
dim i,sel
sel=false
'msgbox theform.c1.length
for i=0 to theform.c1.length-1
if theform.c1(i).checked then
sel=true
exit for
end if
next
If sel Then
TheForm.Submit() ' 数据输入正确,传递到服务器。
else
msgbox "请进行选择"
End If
End Sub
-->
</SCRIPT>
</HEAD>
<BODY>
<H3>简单验证</H3><HR>
<FORM NAME="ValidForm">
<input type=checkbox name=c1 value="2">2<br>
<input type=checkbox name=c1 value="3">3<br><!--把这两行注释就不对了-->
<input type=checkbox name=c1 value="1">1<br><!--把这两行注释就不对了-->
<INPUT NAME="Submit1" TYPE="BUTTON" VALUE="提交">
<input type="button" name="ch2" VALUE="jump"
我想在浏览器端,验证用户没有进行选择,在用户提交表单时,当有选择时将数据传到服务器处理,没有选择则提 示用户进行选择.于是我写了如下的程序,但是当只有一个checkbox时,就不对了,请高手指点! 简单验证 <!-- Sub Submit1_OnClick Dim TheForm Set TheForm = Document.ValidForm dim i,sel sel=false
<HTML>
<HEAD><TITLE>简单验证</TITLE>
<SCRIPT LANGUAGE="VBScript">
<!--
Sub Submit1_OnClick
Dim TheForm
Set TheForm = Document.ValidForm
dim i,sel
sel=false
if theform.c1.checked then
sel=true
end if
If sel Then
TheForm.Submit() ' 数据输入正确,传递到服务器。
else
msgbox "请进行选择"
End If
End Sub
-->
</SCRIPT>
</HEAD>
<BODY>
<H3>简单验证</H3><HR>
<FORM NAME="ValidForm">
<input type=checkbox name=c1 value="2">2<br/>
<INPUT NAME="Submit1" TYPE="BUTTON" VALUE="提交">
<input type="button" name="ch2" VALUE="jump"
更保险一点的是:
if theform.c1.length=1 then
if theform.c1.checked then
sel=true
exit for
end if
elseif theform.c1.length>1 then
for i=0 to theform.c1.length-1
if theform.c1(i).checked then
sel=true
exit for
end if
next
end if
Sub Submit1_OnClick
Dim TheForm
Set TheForm = Document.ValidForm
dim i,sel
sel=false
'msgbox theform.c1.length
select case theform.c1.length
case 1
if theform.c1.checked then
sel=true
exit for
end if
case else
for i=0 to theform.c1.length-1
if theform.c1(i).checked then
sel=true
exit for
end if
next
end select
If sel Then
TheForm.Submit() ' 数据输入正确,传递到服务器。
else
msgbox "请进行选择"
End If
End Sub