jQuery 3 - Home Page

Fill In The Blank
Views 177

Answer:

1. jQuery 3 - Home Page

• Write a function login() that will redirect to home.html after clicking the login button.

• Use username= "admin", and password="password". Else, show an alert message "You are not a valid user".

• Make sure you use the doRedirect() function provided in the index.js file to redirect from index.html to home.html.

index.html

<html>
<head>
    <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>

<div class="login-page">
  <div class="form">
    
      <input type="text" id="username" placeholder="username"/>
      <input type="password" id="password" placeholder="password"/>
      <button id="login" onclick="login()">LOGIN</button>
    
  </div> 
</div>

    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="index.js"></script>
</body>
</html>

script.js

Write your code in this function


function login() {
   
 
};


function doRedirect(href) {

 window.location = href;
 
};
script.js

Updated Code


 

 function login() {
  var username = $('#username').val();
  var password = $('#password').val();

  if (username === "admin" && password === "password") {
    doRedirect('home.html');
  } else {
    alert("You are not a valid user");
  }
}

function doRedirect(href) {
 window.location = href;
};

Related Articles:

This section is dedicated exclusively to Questions & Answers. For an in-depth exploration of jQuery, click the links and dive deeper into this subject.

Join Our telegram group to ask Questions

Click below button to join our groups.