mercredi 4 juillet 2018

If variable=string always returns true

I am having trouble with my javascript.

function login() {
  var username = document.getElementById("username").value;
  var password = document.getElementById("password").value;
  var combine = (username + password)
  if (combine = "userpassword") 
    alert("Logged in.")
  } else {
      alert("Incorrect username or Password.")
  }
}
<!DOCTYPE HTML>
<html>
<body>
<form id="login" onsubmit="return false;">
Username:<br>
<input type="text" name="username" id="username"><br>
Password:<br>
<input type="text" name="password" id="password"><br>
<input type="submit" type="POST" onclick="login();" />
</form>
As you can see, This is a login form. If i type it right, I get "Logged in." But if i type t wrong; I get the same message. Any suggestions would be appreciated.

Aucun commentaire:

Enregistrer un commentaire