这是我的登录表单,另存为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>
提前致谢,
尝试:
function validateForm()
{
var x=document.n_form.name.value;
var y=document.n_form.password.value;
if (x==null || x=="" && y==null || y=="")
{
alert("Form must be filled.");
return false;
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句