回 帖 发 新 帖 刷新版面

主题:关于表单检测的一个问题

<%@ 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">&nbsp;</p>
  <p class="style1"><span class="style5">密码</span>    
    <input type="password" name="password1"> 
  (不能少于6位)</p>
  <p class="style1">&nbsp;</p>
  <p class="style1"><span class="style5">确认密码</span>    
    <input type="password" name="password2"> 
  </p>
  <p class="style1">&nbsp;  </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">&nbsp;</p>
  
</form>

</body>
</html>
提交表单后,不能对表单进行检测,为什么呢?请高手指教

回复列表 (共3个回复)

沙发

<form name="form1" method="post" action="http://localhost:8080/ebook/xianshi.jsp" onSubmit="return checkform1(this)">
  =============改成:
  <form name="form1" method="post" action="http://localhost:8080/ebook/xianshi.jsp" onSubmit="return checkform1(this);">   --就OK了

板凳


还是不行

3 楼

给你一个参考
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!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=gb2312" />
<title>管理登入窗口</title>
<style type="text/css">
<!--
.STYLE3 {
    font-size: 18px;
    font-family: "华文行楷";
}
.STYLE4 {color: #ff8040}
.STYLE7 {
    font-size: 24px;
    font-family: "华文行楷";
}
-->
</style>
<script language="JavaScript">
function isValid(form){
    if(form.name.value==""){
        alert("登录名不能为空!");
    return false;
    }
    else if((form.password.value.length<3)||(form.password.value.length>8)){
        alert("密码必须是3-8位字母或数字!");
    return false;
    }
    else {
        return true;
    }
}
</script>
</head>

<body>
<form action="login_confirm.jsp" method="post" name="form1" onSubmit="return isValid(this);">
<table width="727" border="0" cellpadding="0" cellspacing="0">
  <!--DWLayoutTable-->
  <tr>
    <td width="322" height="30">&nbsp;</td>
    <td width="304"></td>
    <td width="101">&nbsp;</td>
  </tr>
  <tr>
    <td height="211">&nbsp;</td>
    <td valign="top"><table width="299" height="173" border="1" cellspacing="4">
      <!--DWLayoutTable-->
        <tr>
          <td height="23" colspan="3" nowrap="nowrap" bgcolor="#FF8040"><div align="center" class="STYLE3"> 中华管理</div></td>
        </tr>
        <tr>
          <td width="61" height="20" bgcolor="#FF8040"><p align="center">用户:</p>          </td>
          <td colspan="2"><label>
            <input name="name" type="text" size="25" maxlength="30" />
          </label></td>
        </tr>
        <tr>
          <td height="20" bgcolor="#FF8040"><div align="center">密码:</div></td>
          <td colspan="2"><label>
            <input name="password" type="password" size="25" maxlength="30"  />
          </label></td>
        </tr>
        <tr>
          <td height="30" colspan="3"> <label>
            </label>
            <label>
<div align="center">
              <input type="submit" name="Submit" value="提交" />
              <input type="reset" name="reset" value="取消" />
  </div>
          </label></td>
        </tr>
        <%
   String getmessage = (String) session.getValue("login_message");
   if(getmessage==null) getmessage="";
    if(getmessage.equals("OK"))
    {
    %>
        <tr>
          <td height="20" colspan="3" valign="top"> <label>
            </label>
            <label>          </label>            <div align="center"><a href="recipe_management.jsp" class="STYLE4"><img src="img/arrow.gif" width="30" height="27" /><span class="STYLE7">中华食谱管理</span></a></div></td>
          </tr>
        <%
        }else if(!getmessage.equals("")){
        %>

        <font color ='#ff8040'>
        <%
        out.println(getmessage);
        %>
        </font>
        <%
        }
        %>
      </table>      </td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td height="62">&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>
</form>
</body>
</html>

我来回复

您尚未登录,请登录后再回复。点此登录或注册