redirect page question
I want to realize follow function.There are one text type area and password type area in a form,after user filled both of them,this form will redirect another page.But if either of two is not filled,this form asks to fill it,and don't redirect another page.I use Javascript to check either of them is null,if it is null,it return false and this form don't redirect another page.But I found it doesn't work,when I don't fill either of them and click submit button,it still redirect another page.Why? My code is follows:
<script language="JavaScript">
<!--
function isEmpty(str)
{
if ((str==null)||(str.length==0))
{
return true;
}
else
{
return false;
}
}
function check()
{
var nickName=window.document.form1.nickName.value;
var pwd=window.document.form1.pwd.value;
if(isEmpty(nickName))
{
alert("Input your name:");
window.document.form1.nikeName.focus();
return false;
}
if(isEmpty(pwd))
{
alert("Input your password:");
window.document.form1.pwd.focus();
return false;
}
}
-->
</script>
<html>
<body bgcolor="#FFFFFF" text="#000000">
<div align="center">
<form name="form1" method="post" action="test.jsp" onsubmit="return check();">
<table width="350" border="0" cellspacing="0">
<tr>
<td width="108" bgcolor="#ffd6c8" height="27">
<div aligh="right">Name:</div>
</td>
<td width="238" bgcolor="#ffd6c8" height="27">
<input type="text" name="nickName" size="20" maxlength="10">
</td>
</tr>
<tr>
<td width="108" bgcolor="#ffd6c8" height="27">
<div aligh="right" >Password:</div>
</td>
<td width="238" bgcolor="#ffd6c8" height="27">
<input type="password" name="pwd" size="20" maxlength="10">
</td>
</tr>
<tr>
<td width="108" bgcolor="#ffd6c8"> </td>
<td width="238" bgcolor="#ffd6c8">
<input type="submit" name="Submit" value="OK">
<input type="reset" name="reset" value="Cancle">
</td>
</tr>
</table>
</form>
</div>
</body>
</html>
Any idea will be appreciated!
Edward
|