I have a login.html file and a main.html file, when I enter the username and password and click login in the login.html, I need it to go to the main.html, using javascript
I have this in the login.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width", initial-scale=1.0>
<title>Login</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<header class="container">
<form class="form" id="login">
<h1 class="form__title">Login</h1>
<div class="form__input-group">
<input type="text" class="form__input" id="username" autofocus placeholder="Username">
</div>
<div class="form__input-group">
<input type="password" class="form__input" id="password" placeholder="Password">
</div>
<button class="form__button" type="submit" onclick="LogIn()">Log in</button>
</form>
</header>
<script src="index.js"></script>
</body>
</html>
this is the javascript
var loginAcc = [
{
username: 'username123',
password: 'password123',
},
{
username: 'username456',
password: 'password456'
}
]
function LogIn() {
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
console.log(`Username: ${username}`);
console.log(`Password: ${password}`);
for(i = 0;i < loginAcc.length; i++) {
if(username == loginAcc[i].username && password == loginAcc[i].password) {
console.log(`${username} is logged in`)
}
}
}
And how do I use javascript to open the main.html once the user has logged in