1

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>
Chris569x
  • 335
  • 1
  • 3
  • 14

1 Answers1

3

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.

Community
  • 1
  • 1
DWB
  • 1,544
  • 2
  • 16
  • 33