Redirect to another page in html after successful login
P粉729518806
P粉729518806 2024-03-20 09:29:07
0
1
378

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粉729518806
P粉729518806

reply all(1)
P粉154798196

You are calling the value using code:

var UserID = document.getElementById("UserID").value;

But the UserID you entered has a space:

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template