【发布时间】:2014-06-17 20:39:38
【问题描述】:
我已经做了一个登录页面。我希望我的 js validateForm() 函数在用户遗漏用户名或密码时提醒他们。这是我目前得到的代码。
<!DOCTYPE html>
<html>
<head>
<script>
function validateForm()
{
var x=document.forms["myForm"]["username"].value;
if (x==null || x=="")
{
alert("Please enter username");
return false;
}
}
</script>
</head>
<div class="users form">
<br>
<form name="myform" action="Employees/login" onsubmit="return validateForm()" method="post" >
<?php
if (isset($error)) {
echo "<p style='color:red;font-size: 20px''>Username or Password is invalid. Please try again.</p>";
}?>
<p>Enter Username:
<input type="text" name="username" placeholder="username" style="height: 25px;width: 160px;"/></p>
<br><br>
<p>Enter Password:
<input type="password" name="password" placeholder="password" style="height: 25px;width: 160px;"/></p>
<br>
<input type="submit" style="height:35px;width:100px;font-size: 18px; align:center;" value="Sign in">
</form>
</div>
目前它不起作用,我认为问题出在代码行 "var x=document.forms["myForm"]["username"].value;"有人可以帮忙吗?
【问题讨论】:
标签: javascript validation