So I am doing a small project and cannot seem to get this function to work. any idea what I am doing wrong?
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="script.js"></script>
<title>Login</title>
</head>
<body>
<form name="loginForm">
<label>Password:</label>
<input type="password" id="passwordField">
<input type="button" value="Login" onclick="checkPassword()">
<p><output id="outputField"></output></p>
</form>
</body>
</html>
here is the script.
var passwordField = "apple"
var checkPassword = function (checkPassword, passwordField) {
if (passwordField == "apple") {
{document.loginForm.outputField.value = "You did it!";}
}
else {
{document.loginForm.outputField.value = "Fail.";}
}
};
checkPasswordparameter to your function--that's its name. Also, you're callingcheckPasswordon the click, but not passing it any parameter. Why would you expect it to work? By the way,if-elseis not a function, it's a statement.