<html>
<head>
<script type="text/javascript">
function test()
{
if(form1.uname.value=="")
{
document.getElementById("errmsg2").innerHTML="<font color='red'>Please enter a valid username</font>";
document.form1.uname.focus();
}
else if(form1.pwd.value=="")
{
document.getElementById("errmsg").innerHTML="<font color='red'>Please enter a valid password</font>";
document.form1.pwd.focus();
}
else if(form1.pwd.value.length<=5)
{
document.getElementById("errmsg1").innerHTML="<font color='red'>Please enter a password of valid length</font>";
document.form1.pwd.focus();
}
}
function Pause()
{
timer = setTimeout("endpause()",3000);
return false;
}
</script>
</head>
<body>
<form name="form1">
<center>
<table cellpadding="10">
<tr>
<td>
<div id="errmsg"></div>
<div id="errmsg1"></div>
<div id="errmsg2"></div>
</td>
</tr>
<tr>
<td>USERNAME:</td>
<td><input type="text" name="uname" size="25"></td>
</tr>
<tr>
<td>PASSWORD:</td>
<td><input type="password" name="pwd" size="25"></td>
</tr>
</table>
<input type="submit" value="Submit" onClick="test()" action="form_action.asp">
<input type="reset" value="Reset">
</center>
</form>
</body>
</html>
The aim is to display error messages if the username field is blank,password field is blank or password field text length is less than 6 characters.I tried doing it using the onBlur event,failed and then did it using submit button's onClick event.The error message is displayed for a split of a second.Kindly help me rectify the errors in both the cases:onClick and onBlur.Thank you in advance.


Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.

Back to top








