Hai Every Body The Following Code will provide the Validations for the simple Login form
Here Is the Following Code
JSP Page
<%--
Document : Login_Form
Created on : 14th Dec, 2012, 6:53:15 PM
Author : Santoshkumar.Patnana
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<script>
function validate(){
var UserName=document.f1.name.value;
var Password= document.f1.pwd.value;
if (UserName==""||UserName==null)
{
alert("Please Enter The Name")
document.f1.name.focus();
return false;
}
if (Password==""||Password==null)
{
alert("Please Enter The Password")
document.f1.pwd.focus();
return false;
}
}
</script>
</head>
<body>
<form action ="Log"name="f1" method="post" >
<table border="1">
<tr>
<td>
Name : <input type="text" size="20" name="name" />
</td>
</tr>
<tr>
<td>
Password : <input type="password" size="20" name="pwd" />
</td>
</tr>
<tr>
<td>
<input type="submit" value="submit" onclick="return validate()"/>
</td>
</tr>
</table>
</form>
</body>
</html>
Document : Login_Form
Created on : 14th Dec, 2012, 6:53:15 PM
Author : Santoshkumar.Patnana
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<script>
function validate(){
var UserName=document.f1.name.value;
var Password= document.f1.pwd.value;
if (UserName==""||UserName==null)
{
alert("Please Enter The Name")
document.f1.name.focus();
return false;
}
if (Password==""||Password==null)
{
alert("Please Enter The Password")
document.f1.pwd.focus();
return false;
}
}
</script>
</head>
<body>
<form action ="Log"name="f1" method="post" >
<table border="1">
<tr>
<td>
Name : <input type="text" size="20" name="name" />
</td>
</tr>
<tr>
<td>
Password : <input type="password" size="20" name="pwd" />
</td>
</tr>
<tr>
<td>
<input type="submit" value="submit" onclick="return validate()"/>
</td>
</tr>
</table>
</form>
</body>
</html>