这是我保存为 n_form.html 的登录表单。我正在尝试检查空字段,但是每当我单击登录而不填写字段时,我的表单都会重定向到下一页而不是发送消息。请帮忙。
<!DOCTYPE html>
<html>
<head>
<title>Registration Form Of Teknack</title>
<link rel="stylesheet" type="text/css" media="screen" href="css-page.css" />
<script language="Javascript">
function validateForm(){
var x=document.forms["n_form"]["Username"].value;
var y=document.forms["n_form"]["Password"].value;
if (x==null || x=="" & y==null || y==" "){
alert("Form must be filled.");
return false;
}
}
</script>
</head>
<body>
<br><br><br>
<form name="n_form" action="form.php" onclick="return validateForm()" method="post">
<ol>
<li>Username<br>
<input id="width" type="text" name="name" value="" /></li>
<li><br>Password<br>
<input id="width" type="password" name="password" value="" /></li>
<li><br>
<input type="checkbox" value="">Remember me<br></li>
<li id="login">
<br><button type="submit">Login</button></li>
</ol>
</form>
</body>
</html>
提前致谢,