0

我有以下表格和以下 javascript 代码。验证不起作用。我正在使用 jsp 和 netbeans。请帮忙。

文件 StudentLogin.jsp 是-

<%-- 
    Document   : StudentLogin
    Created on : Sep 8, 2013, 10:24:07 PM
    Author     : user1
--%>
<script type="text/javascript" src="js/uservalidation.js"></script>
<script type="text/javascript" language="JavaScript">

function HidePart(d) { document.getElementById(d).style.display = "none";  }
function ShowPart(d) { document.getElementById(d).style.display = "block"; }
function CheckboxChecked(b,d)
{
   if(b) { ShowPart(d); }
   else  { HidePart(d); }
}
</script>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@include file="header.html" %>
<%@include  file="includes/mainmenu.jsp" %>
       <form action="./StudentLogin" method="POST" name="loginForm" onSubmit="return valide();">
            <table align='center'>
            <th colspan='2' align='center'>LOGIN</th>
            <tr><td><b>StudentID:</b></td><td> <input type="text" name="studentId" MAXLENGTH="15"></td></tr>
            <tr><td><b>Username:</b></td><td> <input type="text" name="username" MAXLENGTH="15"></td></tr>
            <tr><td><b>Password:</b></td><td> <input type="password" name="password" MAXLENGTH="15"></td></tr>
            <tr><td>&nbsp</td><td>&nbsp</td></tr>
            <tr><td><input type="submit" name="action" value="Submit"></td><td align='right'><input type="reset"></td></tr>
            </table>
    </form>
<%@include  file="includes/footer.jsp" %>

uservalidation.js 文件如下-

function valide()
{
var studentID = document.forms["LoginForm"]["studentId"].value;
var username=document.forms["loginForm"]["username"].value;
var password=document.forms["loginForm"]["password"].value;

      if(studentID==null || studentID == "" || studentID.length<6){
        alert("Invalid Student ID");
        return false;
        }

    else if(username==null || username == "" || username.length<5)
        {
        alert("Username too short");
        return false;
        }
    else if(password == null || password == "" || password.length<2)
        {
        alert("Password too short");
        return false;
        }

}
4

0 回答 0