I have an input for username and one for password. When the username and/or password don't match, I successfully get the "alert", but when they do match, nothing happens. I can't figure out what I'm doing wrong.
I have tried windows.location.replace
as well, with the same results.
function user1() {
var user = document.getElementById('username').value
var pass = document.getElementById('password').value
if (user == "admin" && pass == "password1") {
window.location ("http://stackoverflow.com");
}
else {
alert('incorrect username or password')
}
}
<form>
<label for="username" id="user">User</label>
<input type="text" placeholder="Username" name="username" id="username">
<br>
<label for="password">Pass</label>
<input type="password" name="password" id="password" placeholder="Password">
<br>
<button onclick="user1()">Submit</button>
</form>
Aucun commentaire:
Enregistrer un commentaire