<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>JS验证表单内容</title>
<script type="text/javascript">
function validNull(theId,msg){
if(document.getElementById(theId).value=="")
{
window.alert(msg);
document.getElementById(theId).focus();
return true;
}
}
function submitCheck(){
if (validNull("Sch_Ename","请输入学校英文名称!"))
{
return;
}
if (validNull("Sch_Addr","请输入学校地址!"))
{
return;
}
if (validNull("Sch_Country","请选择学校所在国家!"))
{
return;
}
if (validNull("Sch_Property","请选择学校性质!"))
{
return;
}
if (validNull("Sch_Stay","请选择住宿服务类型!"))
{
return;
}
window.alert("验证通过")
}
</script>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
学校英文名称:<label><input type="text" name="Sch_Ename" /></label> <br />
学校地址:<label><input type="text" name="Sch_Addr" /></label><br />
学校所在国家:<label><input type="text" name="Sch_Country" /></label><br />
学校性质:<label><input type="text" name="Sch_Property" /></label><br />
住宿服务类型:<label><input type="text" name="Sch_Stay" /></label><br />
<label><input type="submit" name="submit" onclick="submitCheck()" /></label>
<label><input type="reset" name="reset" value="reset" /></label>
</form>
</body>
</html>
////html文件,很好测试的,高人帮下忙吧。看了半天没找出错误
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>JS验证表单内容</title>
<script type="text/javascript">
function validNull(theId,msg){
if(document.getElementById(theId).value=="")
{
window.alert(msg);
document.getElementById(theId).focus();
return true;
}
}
function submitCheck(){
if (validNull("Sch_Ename","请输入学校英文名称!"))
{
return;
}
if (validNull("Sch_Addr","请输入学校地址!"))
{
return;
}
if (validNull("Sch_Country","请选择学校所在国家!"))
{
return;
}
if (validNull("Sch_Property","请选择学校性质!"))
{
return;
}
if (validNull("Sch_Stay","请选择住宿服务类型!"))
{
return;
}
window.alert("验证通过")
}
</script>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
学校英文名称:<label><input type="text" name="Sch_Ename" /></label> <br />
学校地址:<label><input type="text" name="Sch_Addr" /></label><br />
学校所在国家:<label><input type="text" name="Sch_Country" /></label><br />
学校性质:<label><input type="text" name="Sch_Property" /></label><br />
住宿服务类型:<label><input type="text" name="Sch_Stay" /></label><br />
<label><input type="submit" name="submit" onclick="submitCheck()" /></label>
<label><input type="reset" name="reset" value="reset" /></label>
</form>
</body>
</html>
////html文件,很好测试的,高人帮下忙吧。看了半天没找出错误
<input type="submit" name="submit" onclick="return submitCheck()" /> </label> 2、:把JS中所有的return 和return true改为return false
{
return false;
} 都加上还有最好每个input加上ID
学校英文名称: <label> <input type="text" id="Sch_Ename" /> </label> <br />
学校地址: <label> <input type="text" id="Sch_Addr" /> </label> <br />
学校所在国家: <label> <input type="text" id="Sch_Country" /> </label> <br />
学校性质: <label> <input type="text" id="Sch_Property" /> </label> <br />
住宿服务类型: <label> <input type="text" id="Sch_Stay" /> </label> <br />
<label> <input type="submit" name="submit" onclick="submitCheck()" /> </label>
<label> <input type="reset" name="reset" value="reset" /> </label>
</form>
</body>
<script type="text/javascript">
function validchk(f){
with(f){
if(Sch_Ename.value.length==0){alert("请输入学校英文名称!");Sch_Ename.focus();return false;}
if(Sch_Addr.value.length==0){alert("请输入学校地址!");Sch_Addr.focus();return false;}
if(Sch_Country.value.length==0){alert("请选择学校所在国家!");Sch_Country.focus();return false;}
if(Sch_Property.value.length==0){alert("请选择学校性质!");Sch_Property.focus();return false;}
if(Sch_Stay.value.length==0){alert("请选择住宿服务类型!");Sch_Stay.focus();return false;}
}
window.alert("验证通过")
}
</script>
</head>
<body>
<form id="form1" name="form1" method="post" action="" onsubmit="validchk(this);">
学校英文名称: <label> <input type="text" name="Sch_Ename" /> </label> <br />
学校地址: <label> <input type="text" name="Sch_Addr" /> </label> <br />
学校所在国家: <label> <input type="text" name="Sch_Country" /> </label> <br />
学校性质: <label> <input type="text" name="Sch_Property" /> </label> <br />
住宿服务类型: <label> <input type="text" name="Sch_Stay" /> </label> <br />
<label> <input type="submit" name="submit" /> </label>
<label> <input type="reset" name="reset" value="reset" /> </label>
</form>
</body>
</html>
if(document.getElementById(theId).value=="")
{
window.alert(msg);
document.getElementById(theId).focus();
return true;
}
}
function submitCheck(){
if (validNull("Sch_Ename","请输入学校英文名称!"))
{
return false;
}
if (validNull("Sch_Addr","请输入学校地址!"))
{
return false;
}
if (validNull("Sch_Country","请选择学校所在国家!"))
{
return false;
}
if (validNull("Sch_Property","请选择学校性质!"))
{
return false;
}
if (validNull("Sch_Stay","请选择住宿服务类型!"))
{
return false;
}
window.alert("验证通过");
return true;
} <form id="form1" name="form1" method="post" action="" onsubmit="return submitCheck();">
学校英文名称: <label> <input type="text" id="Sch_Ename" name="Sch_Ename" /> </label> <br />
学校地址: <label> <input type="text" id="Sch_Addr" name="Sch_Addr" /> </label> <br />
学校所在国家: <label> <input type="text" id="Sch_Country" name="Sch_Country" /> </label> <br />
学校性质: <label> <input type="text" id="Sch_Property" name="Sch_Property" /> </label> <br />
住宿服务类型: <label> <input type="text" id="Sch_Stay" name="Sch_Stay" /> </label> <br />
<label> <input type="submit" name="submit"/> </label>
<label> <input type="reset" name="reset" value="reset" /> </label>
</form>