I can't redirect to another page, all it does is show the password and user I entered in the url. However, when I use window.open(); it does work in links like YouTube. I've tried various codes I've seen on youtube but I still don't 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>
P粉1547981962024-03-21 00:41:45
You are calling the value using code:
var UserID = document.getElementById("UserID").value;
But the UserID you entered has a space: