JavaScript验证无法在jsp文件中运行

时间:2013-09-09 06:19:38

标签: javascript jsp netbeans

我有以下表格和以下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;
        }

}

0 个答案:

没有答案