I am trying to have a website display different messages depending on whether the password entered is correct or not (correct password is thePassword). So far, no luck.
According to Chrome, the error is in this line (first line of the function):
if (document.getElementById("psw") = "thePassword") {
JSFiddle: https://jsfiddle.net/5grtmxd4/
Thanks in advance!
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form>
Password<br>
<input id="psw" type="password" name="password" size="45" autofocus></input><br><br>
<input type="submit" value="Submit" onclick="message();"></input>
</form>
<script>
function message () {
if (document.getElementById("psw") = "thePassword") {
document.getElementById("display").innerHTML = "Logged in";
} else {
document.getElementById("display").innerHTML = "Try again!";
}}
</script>
<p id="display"></p>
</body>
</html>
EDIT: I would appreciate that instead of trying to rewrite the entire code, only neccessary changes are made. Thanks!