I am trying to make a login using js, I know this isn't secure it's just for school - they require it.
If username and password are correct I want it to open my photos page, this isn't happening.
As far as I can tell everything else is working just fine, it collects and compares data correctly, but won't open the new page. I have tried variations on the this.location.href such as window.location and location.replace.
I have also tried changing the URL using full URL and photos.php
The function is called from a click within the HTML :
<button type="submit" onclick="checkPassword()" class="button">Login</button>
This is the JavaScript:
function check() { //onclick
var username = "test";
var password = "admin";
var usernameEntered = document.getElementById("username").value;
var passwordEntered = document.getElementById("password").value;
if (usernameEntered == username && passwordEntered == password) {
this.location.href = "http://localhost/photos-v4/photos.php";
} else {
alert("Incorrect username or password");
}
}
"cannot read property location of undefined"?window.open('http://www.google.com');