jQuery Hands-on 2 - Login Page

jQuery >   jQuery Event Handling >   jQuery Event Handling  

Long Question

529


Answer:

1. jQuery Hands-on 2 - Login Page

Write a function login() that will read the username and password from the text boxes IDs #username, #password, and validate them.

For username="admin" and password= "password", create an alert box "You are a valid user", or "You are not a valid user".

index.html

<html>
<head>
    <link rel="stylesheet" type="text/css" href="style.css">
    <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>
   
    
</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" type="button" onclick="login()">Login</button></br>
   
  </div> 
</div>
 
    
</body>
</html>
script.js

function login() {
   
      
};

script.js

Here is the implementation of the login function in JavaScript:


 function login() {
  var username = $("#username").val();
  var password = $("#password").val();
  
  if (username == "admin" && password == "password") {
    alert("You are a valid user");
  } else {
    alert("You are not a valid user");
  }
};


This Particular section is dedicated to Question & Answer only. If you want learn more about jQuery. Then you can visit below links to get more depth on this subject.




Join Our telegram group to ask Questions

Click below button to join our groups.