I have made an login form and in that i m using JavaScript for checking validations. But the coding which i have done is just checking the validations for the first field ie User name & it is not checking whether the password field is left blank or not or it is not even checking other validations also.
the coding goes here :-
<html>
<head>
<title>The form</title>
<SCRIPT LANGUAGE=JavaScript>
<!--
function validate()
{
if ( isName() && isPass())
{
document.login.submit();
}
return true;
}
function isName()
{
var str = document.login.firstname.value;
if (str == "")
{
alert("\nThe Login Name field is blank .\n\nPlease re-enter your Login Name.")
document.login.firstname.focus();
return false;
}
}
function isPass()
{
var str = document.login.passwd.value;
if (str == "")
{
alert("\nThe PASSWORD field is empty")
document.login.passwd.focus();
return false;
}
if (str.length < 4)
{
alert("The PASSWORD field has less than 4 chars.\n Please re-enter your Password.")
document.login.passwd.focus();
return false;
}
}
//-->
</SCRIPT>
</head>
<BODY bgcolor="#5e9eff" background="C:\image001.jpg"><p>
<center><br><br><br><br><br><br>
<h2>Welcome to the Login Form</h2><br>
<form name="login">
<table border=14 bgcolor="#CCCCCC" >
<tr><th>
<font color="red">
Enter LoginName :
</th>
<td>
<input type="text" maxLength=20 value="" name="firstname">
</td></tr>
<tr><th>
<font color="red">
Enter Password :</th>
<td>
<input type="password" value="" name="passwd" maxLength=12></td>
</tr>
<tr>
<td colspan=2>
<input type="button" value="Submit" name="submit" onClick="validate()">
<input type="reset" value="Reset" name="reset"></td></tr>
<tr>
<th colspan=2>
<a href="email.html"><font size=2><face="times"><i>New User For Registration click here
</font></a></th></tr>
</form>
</body>
</html>
the coding goes here :-
<html>
<head>
<title>The form</title>
<SCRIPT LANGUAGE=JavaScript>
<!--
function validate()
{
if ( isName() && isPass())
{
document.login.submit();
}
return true;
}
function isName()
{
var str = document.login.firstname.value;
if (str == "")
{
alert("\nThe Login Name field is blank .\n\nPlease re-enter your Login Name.")
document.login.firstname.focus();
return false;
}
}
function isPass()
{
var str = document.login.passwd.value;
if (str == "")
{
alert("\nThe PASSWORD field is empty")
document.login.passwd.focus();
return false;
}
if (str.length < 4)
{
alert("The PASSWORD field has less than 4 chars.\n Please re-enter your Password.")
document.login.passwd.focus();
return false;
}
}
//-->
</SCRIPT>
</head>
<BODY bgcolor="#5e9eff" background="C:\image001.jpg"><p>
<center><br><br><br><br><br><br>
<h2>Welcome to the Login Form</h2><br>
<form name="login">
<table border=14 bgcolor="#CCCCCC" >
<tr><th>
<font color="red">
Enter LoginName :
</th>
<td>
<input type="text" maxLength=20 value="" name="firstname">
</td></tr>
<tr><th>
<font color="red">
Enter Password :</th>
<td>
<input type="password" value="" name="passwd" maxLength=12></td>
</tr>
<tr>
<td colspan=2>
<input type="button" value="Submit" name="submit" onClick="validate()">
<input type="reset" value="Reset" name="reset"></td></tr>
<tr>
<th colspan=2>
<a href="email.html"><font size=2><face="times"><i>New User For Registration click here
</font></a></th></tr>
</form>
</body>
</html>
Comment