✏️ Explanatory Question
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() {
};
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");
}
};