I'm starting to feel less smart by the minute. Anyway, I have yet another Javascript problem. This one needs to be answered quickly, so just do what you guys do best: answer my questions quickly. Anyway, here's my code:
<form>
<p>Password :
<input type="password" name="text1" id="Pass">
</p>
<p><input type="button" value="Submit" name="Submit" onclick=javascript:check() >
</p>
</form>
<script>
var Password = "Pop";
function check()
{
if (document.getElementById('Pass') == Password)
load('Game.htm');
else {
alert('Incorect username/password. Please try again.');
}
}
function load(url)
{
location.href=url;
}
</script>I left out all the fun CSS and things like that. It's supposed to Bring you to some other document if you type "Pop" as the password. It always says I'm wrong.
I hope you guys can help (like you always have)!

Offline
document.getElementById('Pass').value will work
getElementById just returns the element itself, you then need to ask for its value.
P.S. You should use onclick="action()" rather than javascript:action(). Also, use the <html><head><body> syntax to keep your code clean, and put in type="text/javascript" in your script definitions.
Last edited by Hardmath123 (2012-05-28 12:22:31)
Offline
Hardmath123 wrote:
document.getElementById('Pass').value will work
getElementById just returns the element itself, you then need to ask for its value.
P.S. You should use onclick="action()" rather than javascript:action(). Also, use the <html><head><body> syntax to keep your code clean, and put in type="text/javascript" in your script definitions.![]()
Awesome! Thanks! (*Whistles* "I knew those guys were quick").

Offline
PullJosh wrote:
Hardmath123 wrote:
document.getElementById('Pass').value will work
getElementById just returns the element itself, you then need to ask for its value.
P.S. You should use onclick="action()" rather than javascript:action(). Also, use the <html><head><body> syntax to keep your code clean, and put in type="text/javascript" in your script definitions.![]()
Awesome! Thanks! (*Whistles* "I knew those guys were quick").
![]()
And javascript is not the best way to store passwords, because anyone can simply view the source and get around it.
Offline
SJRCS_011 wrote:
PullJosh wrote:
Hardmath123 wrote:
document.getElementById('Pass').value will work
getElementById just returns the element itself, you then need to ask for its value.
P.S. You should use onclick="action()" rather than javascript:action(). Also, use the <html><head><body> syntax to keep your code clean, and put in type="text/javascript" in your script definitions.![]()
Awesome! Thanks! (*Whistles* "I knew those guys were quick").
![]()
And javascript is not the best way to store passwords, because anyone can simply view the source and get around it.
If you use ajax, you can use a php script to echo a password, but only if the current url isnt where the php script is. That way, nobody can view the password. However, i can think of a few ways to get around this, too.
Offline
PullJosh wrote:
Hardmath123 wrote:
document.getElementById('Pass').value will work
getElementById just returns the element itself, you then need to ask for its value.
P.S. You should use onclick="action()" rather than javascript:action(). Also, use the <html><head><body> syntax to keep your code clean, and put in type="text/javascript" in your script definitions.![]()
Awesome! Thanks! (*Whistles* "I knew those guys were quick").
![]()
You're welcome.
Offline
sparks wrote:
Yeah, don't store your passwords with Javascript!
Use PHP which will keep it hidden from viewers
![]()
Yeah. It's for some average fourth-graders, though. I don't think the average fourth-grader knows that.

Offline