I have a javascript file in web/js/Validation.js directory. In my Login.jsp, I am calling this .js file to validate username. This does not seem to be working, please can you help.
I've tried using src="/js/Validation.js" and even changing script tag location (ie. between html and head tags) without any luck.
thanks.
Validation.js
function simple_Validation()
{
var valid = true;
if (document.login_form.user.value.lenght == 0)
{
alert ("Pleaes type username");
valid = false;
}
return valid;
}
Login.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript" src="js/Validation.js">
</script>
<title>Login</title>
</head>
<body>
<form name="login_form" action="LoginServlet" method="post"
onSubmit="return simple_Validation();">
<table border="0">
<tr align="left" valign="top">
<td>User Name:</td>
<td><input type="text" name="user" class="inputbox" /></td>
</tr>
<tr align="left" valign="top">
<td>Password:</td>
<td><input type="password" name="pass" class="inputbox" /></td>
</tr>
<tr align="left" valign="top">
<td></td>
<td><input type="submit" name="submit" value="Login" /></td>
</tr>
</table>
<c:out value="${loginresult}">
</c:out>
</form>
</body>
</html>
lengthwrong in your example.