新手求解:简单表单验证,帮我改下哪错了。
vbscript吧
全部回复
仅看楼主
level 1
kakac9527 楼主
姓名不能为空,不超过10字符。
年龄只能为数字,必须大于10.
                 这是我编的,哪错了?
<html>
<script language="vbscript">
sub button1_onclick()
dim theform
set theform=document.validform
if theform.name.value="" or len(document.theform.name.value)>10 
msgbox"姓名不能为空且最多为五个汉字!"
exit sub
end if
if isnumeric(theform.age.value) then
if theform.age.value<=10
msgbox"请在年龄框中输入一个大于10的数字!"
else
msgbox"验证通过,请按键提交!"
  end if
else
msgbox"请在年龄框输入数字!"
end if
theform.submit
end sub
</script>
</head>
<body>
<form  name="validform" method="post" action="if.html">
  <p>
    <label>姓名:
    <input name="nmae" type="text" id="nmae" />
    </label>
  </p>
  <p>
    <label>年龄:
    <input name="age" type="text" id="age" />
    </label>
  </p>
  <p>
    <input type="button" name="button1" value="提交" onc />
  </p>
</form>
</body>
</html>

2009年09月29日 09点09分 1
level 4
<html>
<head>
<script language="vbscript">
<!--
sub button1_onclick()
 dim theform
 set theform = document.validform
 if theform.name.value="" or len(theform.name.value)>10 then
  msgbox "姓名不能为空且最多为五个汉字!"
  exit sub
 end if
 if isnumeric(theform.age.value) then
  if theform.age.value<=10 then
     msgbox "请在年龄框中输入一个大于10的数字!"
  else
     msgbox"验证通过,请按键提交!"
     theform.submit
  end if
 else
  msgbox"请在年龄框输入数字!"
  end if
end sub
-->
</script>
</head>
<body>
<form  name="validform" method="post" action="if.html">
  <p>
    <label>姓名:</label>
    <input name="name" type="text" id="name">
    
  </p>
  <p>
    <label>年龄: </label>
    <input name="age" type="text" id="age" >
   
  </p>
  <p>
    <input type="button" name="button1" value="提交">
  </p>
</form>
</body>
</html>
2009年10月13日 05点10分 2
level 4
我也是个新手,我从新手的角度看了一下,我觉得你这段有以下错误:
1.首先我只看到</head> 却没看到<head>
2.有两个if语句没有then :if theform.name.value="" or len(theform.name.value)>10 和if theform.age.value<=10 这两处没有写then
3.里面有拼写错误  :   <label>姓名:
    <input name="nmae" type="text" id="nmae" /> 这里按你上面写的sub来看应该是name 你写成了nmae
4.if theform.name.value="" or len(document.theform.name.value)>10 这句里的or后面的应该写成document.validform.name.value或theform.name.value
2楼是我更正后的,也欢迎高手赐教,呵呵
2009年10月13日 05点10分 3
1