skip to Main Content

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


  1. You are calling the value with the code :

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

    But there’s a space on you UserID input :

    <input type="text"
         name="id"
         id="User ID" //from id="User ID" to id="UserID"
         placeholder="User ID"
         required />
    
    Login or Signup to reply.
  2. becuse you input id is User ID you can edit it UserId
    enter image description here

    enter image description here
    When writing JavaScript code, one should be good at observing console information

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search