i made a simple login website that uses javascript to run a function that checks username and password:
the website:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Mosswood Herb</title>
<link rel="stylesheet" href="loginPage.css">
<script src="loginPage.js"></script>
</head>
<body>
<form class="box" action="index.html" method="post">
<h1>Login</h1>
<input type="text" id="username" name="username" placeholder="username">
<input type="password" id="password" name="password" placeholder="password">
<input type="submit" name="" value="submit" onclick=submitBtn()>
</form>
</body>
</html>
and the javascript:
let user, pass;
function submitBtn() {
user = document.getElementById("username").value;
pass = document.getElementById("password").value;
if (user == 'oleg' && pass == 'oleg') {
window.location.replace('https://www.youtube.com/')
} else {
alert('Incorrect Username or Password');
}
}
document.addEventListener('keypress', logKey);
function logKey(e) {
if (e.key == 'Enter') {
submitBtn();
} else {}
}
the website functions normally, and will display an error message saying 'invalid' when the username and pass is not reached. however, when the user and pass is correct, it will not redirect me to youtube.com? not too sure why it's happening
P.S the indentation is correct, only had to change it because stack overflow are tedious ;)