I'm trying to do form validation with the following code but it doesn't seem to work. What may be the problem here? How can I fix it? What am I missing?
The condition is that both the username and password must be "CS" and only then should the user be able to login. When they enter the correct username and password, they should be redirected to this page: C:\Users\Anirudha\Desktop\Latex++2\Latex+++
My code looks like this:
<!DOCTYPE html>
<html>
<head>
<title> LOGIN Form</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/bootstrap.css">
<link href='https://fonts.googleapis.com/css?family=Oxygen:400,300,700' rel='stylesheet' type='text/css'>
<style>
body{
margin:0;
padding:0;
background:url("ack.jpeg");
background-size: cover;
font-family: sans-serif;
}
.loginbox{ width: 320px;
height: 450px;
background: #000;
color: #fff;
top:20%;
left:36%;
position:absolute;
transform: translate{-50%,-50%}
box-sizing: border-box;
padding: 70px 30px;
opacity:.7;
}
.avatar{ width: 100px;
height: 100px;
border-radius:50%;
position:absolute;
top:-14%;
left:calc(50% - 50px);
}
h1{ margin:0;
padding: 0 0 20px;
text-align: center;
font-size: 30px;
font-family:AR JULIAN;
color:red;
}
.loginbox p{ margin:0;
padding: 0;
font-weight:bold;
}
.loginbox input{width: 100%;
margin-bottom:20px;
}
.loginbox input[type="text"], input[type="password"]{
border: none;
border-bottom: 1px solid #fff;
background: transparent;
outline:none;
height:40px;
color:#fff;
font-size:16px;
}
.loginbox input[type="submit"]{
border: none;
outline:none;
height:40px;
background:#fb2525;
color: #fff;
font-size:18px;
border-radius:20px;
}
.loginbox input[type="submit"]:hover
{ cursor:pointer;
background:#ffc107;
color:#000;
}
.loginbox a{
text-decoration:none;
font-size:12px;
line-height:20px;
color: darkgrey;
}
.loginbox a:hover
{
color:#ffc107;
}
.active{
color:#fff;
background:#e02626;
border-radius:4px;
}
</style>
</head>
<body>
<img class="log">
<div class="loginbox">
<img src="avatar1.png" class="avatar">
<h1>Login Here</h1>
<script>
function validateform(){
var name=document.myform.name.value;
var password=document.myform.password.value;
if(name!=CS){
alert("Enter the Username as mentioned ");
return false;
}
else if(password!=CS){
alert("Enter the Password as mentioned ");
return false;
}
}
</script>
<form name="myform" method="POST" onsubmit="return validateForm()">
<p> Username</p>
<input type="text" name="name" placeholder="Enter Username: CS319">
<p> Password</p>
<input type="password" name="password" placeholder="Enter Password: CS319"><br>
<input type="submit" name="Login" value="Login">
<a href="file:///C:/Users/Anirudha/Desktop/Latex++2/forgotpwd.html#">Forgot password?</a><br>
<a href="file:///C:/Users/Anirudha/Desktop/Latex++2/CreateAccount.html#">Don't have an acoount?</a>
</form>
</div>
<script src="js/jquery-2.1.4.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/ajax-utils.js"></script>
<script src="js/script.js"></script>
</body>
</html>