how to compare html fields

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dragon52
    New Member
    • Jun 2009
    • 72

    #1

    how to compare html fields

    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 "tbxEmailAddres s" and "tbxEmailAddres s2" are the same. I have the following code
    [code=php]
    cEmailAddress = tbxEmailAddress ;
    cEmailAddress2 = tbxEmailAddress 2;

    }else if (!trim(cEmailAd dress.value) == trim(cEmailAddr ess2.value))
    {
    alert("Please enter the same email address");
    cEmailAddress.f ocus();
    return false;
    }else if (something else)
    [/code]
    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??

    Denis
    Last edited by Atli; Jun 8 '09, 10:19 PM. Reason: Added [code] tags and moved to the JavaScript forum.
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi.

    Assuming you have a form named TestForm, with two fields: Box1 and Box2.
    This would do the trick:
    [code=javascript]function onTestFormSubmi t() {
    var box1 = document.forms. TestForm.Box1;
    var box2 = document.forms. TestForm.Box2;

    if(box1.value != box2.value) {
    alert("Box 1 doesn't match box 2!");
    box1.focus();
    return false;
    }
    return true;
    }[/code]
    You really just had your if statement a bit messed up. (From what I can see, at lest)

    Comment

    Working...