Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simple comparison of 2 text boxes

Status
Not open for further replies.

TheCandyman

Technical User
Sep 9, 2002
761
US
Ya, i know this is simple, but im not sure what i am doing wrong. I want to compare 2 text boxes, if they are not the same display error, clear boxes, and setfocus.


function ValidateForm(){
if (document.form1.pwd.value == document.form1.pwd2.value)
{
alert('The passwords did not match');
document.form1.pwd.value = "";
document.form1.pwd2.value = "";
document.form1.pwd.Setfocus();
return false;
}
}

<form method=&quot;POST&quot; action=&quot;Password_create.asp&quot; onsubmit=&quot;return ValidateForm()&quot; id=form1 name=form1>
<table border=&quot;0&quot; class=&quot;verdana11px&quot; width=&quot;348&quot; height=&quot;305&quot;>
<tr>
<td width=&quot;347&quot; align=&quot;center&quot; height=&quot;22&quot;>
<font size=&quot;2&quot;>Enter a Password</font>
<input type=&quot;password&quot; name=&quot;pwd&quot; size=&quot;15&quot; tabindex=&quot;4&quot;> </td>
</tr>
<tr>
<td width=&quot;347&quot; align=&quot;center&quot; height=&quot;22&quot;>
<font size=&quot;2&quot;>Confirm Password</font>
<input type=&quot;password&quot; name=&quot;pwd2&quot; size=&quot;15&quot; tabindex=&quot;5&quot;> </td>
</tr>

...
...
 
Shouldn't it be this?

if (document.form1.pwd.value != document.form1.pwd2.value)

Adam
while(ignorance==true){perpetuate(violence,fear,hatred);life--};
 
try this for your function


function ValidateForm(){
if (document.form1.pwd.value != document.form1.pwd2.value)
{
alert('The passwords did not match');
document.form1.pwd.value = &quot;&quot;;
document.form1.pwd2.value = &quot;&quot;;
document.form1.pwd.focus();
return false;
}

}
 
First of all, you are only evaluating the block if they are the same, not different. In other words, you are saying if the are the same, alert('they are different').

Secondly, I believe the function is focus(), not setfocus().
 
First == means they are the same So this statement
document.form1.pwd.value == document.form1.pwd2.value
says that if pwd=pwd2 then execute the code with in the block.

I assumed that you do want them to be not equal to execute the code in the block since you have the alert
alert('The passwords did not match');
in the block.

Second Focus does put the cursor in the textbox ( at least in ie).
 
DUH, i can't believe i missed that !=

ARRRRR

you guys are awesome!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top