日期:2014-05-18  浏览次数:20695 次

为什么不能进行验证
这是我编写的源代码,但是就是不能进行验证,请各位大虾帮忙解决

<%@ page contentType="text/html; charset=gb2312" %>

<html>
<head>
<title>考勤信息</title>



</head> 
<script language="JavaScript" >
 <-- function check(){
  if(form.id.value.length<1){
  alter("请重新输入数字编号")
  return false;
  }
  if(form.name.value.length<1){
  alter("不能为空")
  return false;
  }
  if(form.name1.value.length<1){
  alter("请输入数字金额!")
  return false;
  }
  }--> 
</script>
<body>
<center>考勤添加项</center>
<form name ="form" action ="./addsuc.jsp" method= "post" onSubmit="return check()" >
<p align = "center">
编&nbsp;&nbsp;号:
<input type = "text" name = "id" ><BR>
考勤类别:
<input type = "text" name = "name"><BR>
罚&nbsp;&nbsp;金:
<input type = "text" name = "name1"><BR>
</p>  
<p align = "center">  
<input type = "submit" name = "onSubmit" value = "提交">
<input type = "reset" value = "重输">
</p>
<tr></tr>
<tr></tr>
</form>
</body>
</html>

------解决方案--------------------
把你错误信息贴出来看看啊
------解决方案--------------------
你最后也没写return true把这个添加上看看
------解决方案--------------------
<%@ page contentType="text/html; charset=gb2312" % > 

<html > 
<head > 
<title >考勤信息 </title > 



</head >
<script language="JavaScript" > 
<-- function check(form){ 
if(form.id.value.length <1){ 
alter("请重新输入数字编号") 
return false; 

if(form.name.value.length <1){ 
alter("不能为空") 
return false; 

if(form.name1.value.length <1){ 
alter("请输入数字金额!") 
return false; 

return true;
}-- >
</script > 
<body > 
<center >考勤添加项 </center > 
<form name ="form1" action ="./addsuc.jsp" method= "post" onSubmit="return check(this)" > 
<p align = "center" > 
编&nbsp;&nbsp;号: 
<input type = "text" name = "id" > <BR > 
考勤类别: 
<input type = "text" name = "name" > <BR > 
 罚&nbsp;&nbsp;金: 
<input type = "text" name = "name1" > <BR > 
</p >
<p align = "center" >
<input type = "submit" name = "onSubmit" value = "提交" > 
<input type = "reset" value = "重输" > 
</p > 
<tr > </tr > 
<tr > </tr > 
</form > 
</body > 
</html >


试下!!!!