By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,607 Members | 1,758 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,607 IT Pros & Developers. It's quick & easy.

how to compare html fields

P: 72
Hi all,

I am sure this is very common task I can't get it right.

I want to make sure user inputs in 2 text boxes "tbxEmailAddress" and "tbxEmailAddress2" are the same. I have the following code
Expand|Select|Wrap|Line Numbers
  1.     cEmailAddress = tbxEmailAddress;
  2.     cEmailAddress2 = tbxEmailAddress2;
  4. }else if (!trim(cEmailAddress.value) == trim(cEmailAddress2.value))
  5. {
  6.     alert("Please enter the same email address");
  7.     cEmailAddress.focus();
  8.     return false;
  9. }else if (something else)
Problem is this test does nothing even though I know the 2 fields are different.
I want to do this check on the client side.

Can any one help??

Jun 8 '09 #1
Share this Question
Share on Google+
1 Reply

Expert 5K+
P: 5,058

Assuming you have a form named TestForm, with two fields: Box1 and Box2.
This would do the trick:
Expand|Select|Wrap|Line Numbers
  1. function onTestFormSubmit() {
  2.     var box1 = document.forms.TestForm.Box1;
  3.     var box2 = document.forms.TestForm.Box2;
  5.     if(box1.value != box2.value) {
  6.         alert("Box 1 doesn't match box 2!");
  7.         box1.focus();
  8.         return false;
  9.     }
  10.     return true;
  11. }
You really just had your if statement a bit messed up. (From what I can see, at lest)
Jun 8 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.