Reputation: 445
I am trying to do a simple "login" to display a hidden div of a website by having a user input two var (userName and password) and comparing both to declared values.
<script>
function validate() {
var x = document.getElementById("userName").value
var y = document.getElementById("password").value
if (x == "Chris569x") && (y == "DM1986!"){
//Show div
}
else {
window.alert("Incorrect user name/password");
}
}
</script>
<p>DM Login
<br>
<form onSubmit="validate()">
<p>User Name:
<input type="text" id="userName">
<br>
<p>Password:
<input id="password" type="password">
<br></p>
<input name="Login" type="submit" id="Login" title="Login" value="Login" >
</form>
</div>
Upvotes: 1
Views: 63
Reputation: 1554
Your if statement
if (x == "Chris569x") && (y == "DM1986!"){
//Show div
}
Should be
if (x === "Chris569x" && y === "DM1986!"){
//Show div
}
And remember to use tripe equals instead of double.
Upvotes: 3