-
April 29th, 2004, 11:40 PM
#1
Senior Member
javascript password validator
I'm trying to write some javascript that will check that two passwords are equal when they are typed into a form. If not, a pop-up alert id displayed.
However...it doesn't do anything. I'd be grateful for some help.
<script type="text/javascript">
function checkPass()
{
if (document.passwordForm.password.value)==(document.passwordForm.password2.value)
{
//load page
}
else
{
alert("Passwords don't match")
}
}
</script>
<form name="passwordForm">
<p>Enter your name
<input name="password" type="text" id="password">
<input name="password2" type="text" id="password2">
</p>
<p>
<input type="button" value=" Enter" onclick="checkPass()">
</p>
</form>
Mama always said, keep your virus definitions up to date.
-
May 6th, 2004, 11:34 AM
#2
Im not to good at javascript, but like most programming lanaguges it looks like you need to declare the variable??
var a = document.passwordForm.password.value
var b = document.passwordForm.password2.value
if (a == b) alert("correct");
else
{
alert("Passwords don't match")
}
might work, I dont have time to try...
i2c
-
May 6th, 2004, 11:34 AM
#3
Im not to good at javascript, but like most programming lanaguges it looks like you need to declare the variable??
var a = document.passwordForm.password.value
var b = document.passwordForm.password2.value
if (a == b) alert("correct");
else
{
alert("Passwords don't match")
}
might work, I dont have time to try...
i2c
-
May 6th, 2004, 07:42 PM
#4
I made one that worked. I think that your problems were from the weird <SCRIPT> tag. There must have been something else wrong because it still didn't work for me. Anyways, you can take my code and play with it to fit your page.
BTW, just remember that right now, anyone who Views Source of this page can figure out what the next page is.
Enjoy.
Code:
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JAVASCRIPT">
function checkPass()
{
if (document.PassForm.Password1.value == document.PassForm.Password2.value)
{
alert("Good!");
}
else
{
alert("Wrong!");
}
}
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME="PassForm">
Enter your password: <INPUT NAME="Password1"><BR>
Enter your password (again): <INPUT NAME="Password2"><BR>
<INPUT TYPE="BUTTON" VALUE="Enter" ONCLICK="checkPass()">
</FORM>
</BODY>
</HTML>
-
May 6th, 2004, 07:42 PM
#5
I made one that worked. I think that your problems were from the weird <SCRIPT> tag. There must have been something else wrong because it still didn't work for me. Anyways, you can take my code and play with it to fit your page.
BTW, just remember that right now, anyone who Views Source of this page can figure out what the next page is.
Enjoy.
Code:
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JAVASCRIPT">
function checkPass()
{
if (document.PassForm.Password1.value == document.PassForm.Password2.value)
{
alert("Good!");
}
else
{
alert("Wrong!");
}
}
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME="PassForm">
Enter your password: <INPUT NAME="Password1"><BR>
Enter your password (again): <INPUT NAME="Password2"><BR>
<INPUT TYPE="BUTTON" VALUE="Enter" ONCLICK="checkPass()">
</FORM>
</BODY>
</HTML>
-
May 6th, 2004, 10:00 PM
#6
I'm no javascript maestro, but I do know a fair bit of java. I believe your problem is the following (I could be wrong):
Code:
if (document.passwordForm.password.value)==(document.passwordForm.password2.value)
{
//load page
}
Look at your if statement, you have brackets around the variables, but not around your whole statement. If you tried to compile that with a java compiler, it probably wouldn't like that. The correct statement would be:
Code:
if(document.passwordForm.password.value == document.passwordForm.password2.value)
{
// load page
}
Tim, the reason that your code works isn't because of the <SCRIPT> tag, it's because it does not contain the same syntactical mistake. I also didn't have anything to do with not having declared the variables ic2, what djhuk was doing (AFAIK) was taking the text from two fields on an html form. And from the rest of the post, it sounded as if that had already been written...he just posted a code exerpt.
Hope that solves your problem,
ac
-
May 6th, 2004, 10:00 PM
#7
I'm no javascript maestro, but I do know a fair bit of java. I believe your problem is the following (I could be wrong):
Code:
if (document.passwordForm.password.value)==(document.passwordForm.password2.value)
{
//load page
}
Look at your if statement, you have brackets around the variables, but not around your whole statement. If you tried to compile that with a java compiler, it probably wouldn't like that. The correct statement would be:
Code:
if(document.passwordForm.password.value == document.passwordForm.password2.value)
{
// load page
}
Tim, the reason that your code works isn't because of the <SCRIPT> tag, it's because it does not contain the same syntactical mistake. I also didn't have anything to do with not having declared the variables ic2, what djhuk was doing (AFAIK) was taking the text from two fields on an html form. And from the rest of the post, it sounded as if that had already been written...he just posted a code exerpt.
Hope that solves your problem,
ac
-
May 7th, 2004, 01:08 AM
#8
Senior Member
thanks everyone and thanks gothic (you weren't wrong)
-
May 7th, 2004, 01:08 AM
#9
Senior Member
thanks everyone and thanks gothic (you weren't wrong)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|