How to go to another page using only html and css. I have tried with
window.location.href="admin.html";
This statement not working.
<input type="text" value="Username" name="username" /><br>
<input type="text" value="Password" name="password" /><br>
<input type="button" value="Password" name="password" value="Log In" onClick="login()" /><br>
<script>
function login() {
var id = document.getElementById("username").value;
var pass = document.getElementById("password").value;
if (id == "admin" && pass = "admin")
//Redirect to admin page
else if (id == "employee" && pass = "employee")
//Redirect to employee page
}
</script>
You have given the fields a name
, not an id
so your code will throw an error before reaching the redirect.
Is admin.html
in the same scope/folder as this file? If not, you will need to specify the relative path to admin.html
, eg: ../otherFolder/admin.html
Have you tried using window.location.replace(admin.html)
?