I can’t redirect to another page, all it does was show the password and user I entered in the url. It does work however in links such as youtube as I use window.open(); I’ve tried various codes I have watched on youtube but I still dont know what to do
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div class="login-wrapper">
<form action="" class="form">
<h2> Login </h2><br>
<div class="input-group">
<label for="id">User ID </label>
<input type="text"
name="id"
id="User ID"
placeholder="User ID"
required />
</div>
<div class="input-group">
<label>Password </label>
<input type="password"
name="password"
placeholder="Password"
id="password" required />
</div>
<input type="submit" value="Login" class="submit-btn" onclick= "auth()" style="font-size:18px;" />
</form>
</div>
<script>
function auth(){
var UserID = document.getElementById("UserID").value;
var password = document.getElementById("password").value;
if(UserID== "admin" && password=="admin123"){
window.location.href="teachergui.html";
alert("Login Successfully ");
}
else{
alert("Invalid User");
return;
}
}
</script>
</div>
</body>
</html>
2
Answers
You are calling the value with the code :
But there’s a space on you UserID input :
becuse you input id is User ID you can edit it UserId
When writing JavaScript code, one should be good at observing console information