✏️ Explanatory Question
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;
};