Hello Friends,
Consider the following code:
<html>
<head>
<script language="javascript" >
function log2()
{
if(document.login2.cid.value=="")
{
alert("please enter your CID");
return false;
}
}
</script>
</head>
<body bgcolor="#6495ed" text="#000000">
<h1 align="center">Welcome</h1>
<form name="login2" method="POST" onSubmit="log2()"
action="login2.do" >
<br><br>
<center>CID : <input type="text" name="cid" size ="50"></center><br><br>
<center>Password : <input type="password" name ="pwd" size="30"></center><br><br>
<center>
<input type="submit" name="submit" value="Go" >
</center>
</form>
</body>
</html>
Here login2.do maps to a
servlet Login2.java which checks for the validity of the user using Customer ID and password.
I�ve included javascript which alerts the user to enter the CID ,if the user clicks submit button without entering the CID.
But when I actually run the code without entering the CID value and then clicking the submit button ,an alert message is displayed and when I click on OK button of the alert message the request is sent to the servlet (Whereas I want the same page to be displayed so that the user is given another chance to enter CID and pwd)
Cheers,
Poonam.