浏览器表单验证用户名密码非空的js实现

<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'adduser.jsp' starting page</title>
    
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
    <script type="text/javascript" >
        function check(form1){
    if(form1.name.value==""){
        $('userNull').innerHTML = "请输入用户名";form1.name.focus();return false;
    }
    if(form1.pwd.value==""){
        $('pwdNull').innerHTML= '请输入用户密码';form1.pwd.focus();return false;
    }
    if(form1.pwd1.value==""){
        $('VpwdNull').innerHTML = '请确认用户密码';form1.pwd1.focus();return false;
    }        
    if(form1.pwd.value!=form1.pwd1.value){
        $('VpwdNull').innerHTML = '您两次输入的管理员密码不一致,请重新输

入';form1.pwd1.focus();return false;
    }
}
function $(id){
    
    return document.getElementById(id);
}

    </script>

  </head>
  
 
<body>
<form name="form1" method="post" action="<%=path %>/UserAddServlet" onsubmit="return check

(form1);">
    <table height="123"  border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td width="97" height="30" align="center">用户名:</td>
        <td width="178"> <input name="name" type="text">        </td>
        <td width="178"> <span id = 'userNull' style="color:red"></span>       </td>
      </tr>
      <tr>
        <td height="28" align="center">密码:</td>
        <td><input name="pwd" type="password" id="pwd"></td>
        <td><span id ='pwdNull' style="color:red"></span></td>
      </tr>
      <tr>
        <td height="28" align="center">确认密码:</td>
        <td><input name="pwd1" type="password" id="pwd1"></td>
          <td><span id ='VpwdNull' style="color:red"></span></td>
      </tr>
      <tr>
        <td height="37" align="center">&nbsp;</td>
        <td><input name="submit" type="submit" class="btn_grey" value="保存" >
&nbsp;
<input name="submit2" type="reset" class="btn_grey" value="重置" ></td>
      </tr>
    </table>
    </form>

</body>
</html>

 

posted @ 2013-10-19 10:40  EyesFront  阅读(452)  评论(0编辑  收藏  举报