我正在编写一个简单的Javascript表单验证器,但是当我运行它时,它根本没有做任何事情。
function submitFunction()
{
var x = document.forms["myForm"]["username"].value;
var y = document.forms["myForm"]["pwd"].value;
if(x == null || x == "" || y == null || y == "")
{
alert("Both fields cannot be empty");
}
else
{
alert("Username" + x + " Password: " + y);
}
}
我错过了一些简单的东西吗?
它被称为:
<div id="register">
<form name='registration' id="registration" onSubmit="return formValidation()">
Username: <input type="text" name="username"><br>
Password: <input type="password" name="pwd"><br>
<input type="submit" value="Submit">
</form>
</div>