JSP

我在JSP页面上放一个用户名的输入框,和一个提交的Button,然后我想在提交的时候判断输入框内是否有输入内容,如果没有输入内容就不让提交,有输入内容就跳转到另一个页面,但是结果是始终都没有验证就直接提交了。代码如下:
 
<%@ page language="java" contentType="text/html; charset=gb2312"
    pageEncoding="gb2312"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
  <title>Session Test</title>

  <script language="javascript" type="text/javascript">
     function doCheck(){
if(document.frmTest.username.value=""){
    alert("姓名不能为空!");
return false;
}return true;
     }
  </script>
</head><body>
  <form name="frmTest" method="post"  action="sessionpost.jsp"   
     onsubmit="return doCheck();">
     请输入您的姓名:
     <input type="text" name="username" size="10">
     <input type="submit" name="submit" value="提交">
  </form>
</body>
</html>

解决方案 »

  1.   

    function doCheck(){
    if(document.frmTest.username.value=""){
        alert("姓名不能为空!");
    return false;
    }return true;
         }
    这里的return true;错了,换成     function doCheck(){
    if(document.frmTest.username.value=""){
        alert("姓名不能为空!");
    return false;
    } else
                 return true;
         }
      

  2.   

    换成了这样也不行啊,不知道为什么呢。
    而且,上面的  if(document.frmTest.username.value=""){
    if的括号里面document.frmTest.后面的username代不出来,不知道为什么
      

  3.   

    if(document.frmTest.username.value.length==0)
    用这个判断试试看
      

  4.   

    if(document.frmTest.username.value === "") ..
      

  5.   

    这样看可行
    if(document.frmTest.username.value==""){
      

  6.   

    哈哈 if(document.frmTest.username.value=="") VB