0

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" />&nbsp;
<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?

thecodedeveloper.com
3,2505 gold badges40 silver badges69 bronze badges
asked Mar 28, 2013 at 4:50
3
  • You missed a semicolon after var z="dxoincu3rhi". Don't you notice that? Commented Mar 28, 2013 at 4:53
  • is your script123.js file in same folder in which your html file? Commented Mar 28, 2013 at 4:54
  • 1
    I see (at least) two problems with this code in addition to the one @stf pointed out. First, you're not taking .value of z and x, you're just getting the elements themselves. Second, you're using = instead of == for the comparison. Should be if (x.value == "NSDCars5") and if (z.value == "Gryffindor") Commented Mar 28, 2013 at 4:58

2 Answers 2

1

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")

answered Mar 28, 2013 at 5:01
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! That worked perfectly! I'm still a bit new in JavaScript, I need to practice. :D
0

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.

answered Mar 28, 2013 at 5:07

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.