主题:关于表单检测的一个问题
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<script>
function isEmpty(str1)
{
if((str1==null)||(str1.length==0))
return true;
else return(false);
}
function isEmail(str2)
{
var atIndex=str2.indexOf("@");
var dotIndex=str2.indexOf(".",atIndex);
var flag=true;
theSub=str2.substring(0,dotIndex+1);
if((atIndex<1)||(atIndex!=email.lastIndexOf("@"))||(dotIndex<atIndex+2)||(email.length<=theSub.length))
flag=false;
else
flag=true;
return flag;
}
function checkform1(lform)
{
var flag=true;
if(isEmpty(lform.name.value)
{
alert("input your name please");
lform.name.focus();
flag=false;
}
if(!isEmail(lform.email.value))
{
alert("the form of email has something wrong");
lform.email.focus();
flag=flase;
}
return flag;
}
</script>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>会员注册</title>
<style type="text/css">
<!--
.style1 {color: #0000FF}
.style3 {font-family: "黑体", "宋体"; color: #0000FF;}
body {
background-color: #CCDCF4;
}
.style5 {font-size: large}
-->
</style>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->
</script>
</head>
<body>
<div id="Layer1" style="position:absolute; left:484px; top:24px; width:244px; height:77px; z-index:1"><img src="css/index-ebook_clip_image001.gif" width="234" height="74"></div>
<div id="Layer2" style="position:absolute; left:496px; top:117px; width:227px; height:49px; z-index:2">
<h1 class="style3"> Welcome you</h1>
</div>
<form name="form1" method="post" action="http://localhost:8080/ebook/xianshi.jsp" onSubmit="return checkform1(this)">
<p>如果您还没有会员号,请注册</p>
<p class="style1"><span class="style5">用户名</span>
<input name="name" type="text" value="">
</p>
<p class="style1"> </p>
<p class="style1"><span class="style5">密码</span>
<input type="password" name="password1">
(不能少于6位)</p>
<p class="style1"> </p>
<p class="style1"><span class="style5">确认密码</span>
<input type="password" name="password2">
</p>
<p class="style1"> </p>
<p class="style1"><span class="style5">您的邮箱</span>
<input type="text" name="email">
(你取回密码的途径)</p>
<p class="style1">
<input type="submit" name="Submit" value="提交">
<input type="reset" name="Submit" value="重置">
</p>
<p class="style1"> </p>
</form>
</body>
</html>
提交表单后,不能对表单进行检测,为什么呢?请高手指教
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<script>
function isEmpty(str1)
{
if((str1==null)||(str1.length==0))
return true;
else return(false);
}
function isEmail(str2)
{
var atIndex=str2.indexOf("@");
var dotIndex=str2.indexOf(".",atIndex);
var flag=true;
theSub=str2.substring(0,dotIndex+1);
if((atIndex<1)||(atIndex!=email.lastIndexOf("@"))||(dotIndex<atIndex+2)||(email.length<=theSub.length))
flag=false;
else
flag=true;
return flag;
}
function checkform1(lform)
{
var flag=true;
if(isEmpty(lform.name.value)
{
alert("input your name please");
lform.name.focus();
flag=false;
}
if(!isEmail(lform.email.value))
{
alert("the form of email has something wrong");
lform.email.focus();
flag=flase;
}
return flag;
}
</script>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>会员注册</title>
<style type="text/css">
<!--
.style1 {color: #0000FF}
.style3 {font-family: "黑体", "宋体"; color: #0000FF;}
body {
background-color: #CCDCF4;
}
.style5 {font-size: large}
-->
</style>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->
</script>
</head>
<body>
<div id="Layer1" style="position:absolute; left:484px; top:24px; width:244px; height:77px; z-index:1"><img src="css/index-ebook_clip_image001.gif" width="234" height="74"></div>
<div id="Layer2" style="position:absolute; left:496px; top:117px; width:227px; height:49px; z-index:2">
<h1 class="style3"> Welcome you</h1>
</div>
<form name="form1" method="post" action="http://localhost:8080/ebook/xianshi.jsp" onSubmit="return checkform1(this)">
<p>如果您还没有会员号,请注册</p>
<p class="style1"><span class="style5">用户名</span>
<input name="name" type="text" value="">
</p>
<p class="style1"> </p>
<p class="style1"><span class="style5">密码</span>
<input type="password" name="password1">
(不能少于6位)</p>
<p class="style1"> </p>
<p class="style1"><span class="style5">确认密码</span>
<input type="password" name="password2">
</p>
<p class="style1"> </p>
<p class="style1"><span class="style5">您的邮箱</span>
<input type="text" name="email">
(你取回密码的途径)</p>
<p class="style1">
<input type="submit" name="Submit" value="提交">
<input type="reset" name="Submit" value="重置">
</p>
<p class="style1"> </p>
</form>
</body>
</html>
提交表单后,不能对表单进行检测,为什么呢?请高手指教