DEV Community

daksh100sharma
daksh100sharma

Posted on

How to redirect after logged in (simple javascript)

i need some help with my code. Basicaly i am not able to redirect after logged in.
SO i need some help with that.
I used simple html and javascript
html is here and js is down

(index.html)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="login.css">
    <title>Login</title>
    <script src="login.js"></script>
</head>

<body>
     <DIV action="login.html" class="container">
         <form  method="POST" class="login-form">
            <h1 class="login-heading">LOGIN FORM</h1>
             <input type="text" placeholder="User Name" id="login-username">
             <br><br>
             <input type="password" placeholder="Password" id="login-password">
             <br><br><br>
             <input type="submit" value="Login" id="login-submit" onclick="validate()">
         </form>
     </DIV>

</body>
</html>
Enter fullscreen mode Exit fullscreen mode

/*****************/

(script.js)

function validate(){
    var username=document.getElementById('login-username').value;
    var passowrd=document.getElementById('login-password').value;

    if (username === "daksh" && passowrd === 'daksh'){
        alert('You have sucessfully logged in');
        location.href('https://google.com')

    } else{
        alert('Wrong username or password');
    }
}
Enter fullscreen mode Exit fullscreen mode

Discussion (2)

Collapse
daksh100sharma profile image
daksh100sharma Author

? bruh if you can help so help.

Some comments have been hidden by the post's author - find out more