I'm making a basic login page for my website (so people can access only the stuff they need to). The thing is, I've checked the code many times, and there seems to be no problem in it. Yet, the authentication doesn't work. The code:
HTML5:
<!DOCTYPE html>
<html>
<head>
<title>NSDCars5: Login</title>
<script src="script123.js"></script>
<link rel="stylesheet" type="text/css" href="style123.css" />
</head>
<body>
<div id="title">
<h1>Hey, there! Ready for some client-side scripting?</h1>
<h2>So am I! Login here to continue.</h2>
<h4>Or if you're a hacker kind, I'm using JavaScript to validate the form.</h4>
</div>
<div id="content">
<input type="text" id="username" />
<input type="password" id="password" /><br />
<button onclick="checkForPassw()"><img src="icon.png" /></button><br />
</div>
<div id="footer"></div>
</body>
</html>
JavaScript:
function checkForUname() {
var z = document.getElementById("password");
if (z = "Gryffindor") {
var z = "dxoincu3rhi"
self.location = "\hiddencontent.html";
} else {
document.getElementById("result").innerHTML = "You think I'm that stupid!?";
}
}
function checkForPassw() {
var x = document.getElementById("username");
if (x = "NSDCars5") {
var x = "3d3huiun";
checkForUname();
} else {
document.getElementById("result").innerHTML = "You think I'm that stupid!?";
}
}
What's the problem here?
2 Answers 2
Your problem is in the if statement when you are checking for the password and username and what they equal. The if statement should be if(z=="Gryffindor") and if(x=="NSDCars5")
1 Comment
You might need to change the scope of your function. Replace "function checkForPassw() {" with
this.checkForPassw = function() {
And user2218363 is also correct - you will need to add the == operator to compare two values.
var z="dxoincu3rhi". Don't you notice that?if (x.value == "NSDCars5")andif (z.value == "Gryffindor")