SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,406
    Mentioned
    149 Post(s)
    Tagged
    4 Thread(s)

    value compare problem

    I have this script:
    Code JavaScript:
    var value = jQuery(this).attr("value");
    var value2 = jQuery(".my_form #value2 ").attr("value");
    if(value != value2){
      var errorcode = "error -" + value + "-";
      surrounding_element.attr("class","").addClass(errorcode);
      var errorcode = "error -" + value2 + "-";
      jQuery(".my_form #value2 ").parent().attr("class","").addClass(errorcode);
    }else{
      surrounding_element.attr("class","").addClass("valid");	
      jQuery(".my_form #value2 ").parent().attr("class","").addClass("valid");
    }						 }
    If I put exactly the same value in both fields, for example info@thisisafakeemail.fake (I'm testing email addresses), then the result is:
    Code:
    class="error -info@thisisafakeemail.fake-"
    for both elements.
    So it seems to me that value and value2 are identical. But the 'if' says no.
    Why?

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    8,904
    Mentioned
    139 Post(s)
    Tagged
    2 Thread(s)
    Take a good look at this line:

    Code JavaScript:
    var value2 = jQuery(".my_form #value2 ").attr("value");

    More specifically ".my_form #value2--remove-the-space-here--"

  3. #3
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,406
    Mentioned
    149 Post(s)
    Tagged
    4 Thread(s)
    Ok, I got rid of that space, but it makes no difference. Still the same result.

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    if(value != value2){
        alert("'" + value + "':'" + value2 + "'");
    }
    I don't think value is what you expect. If that still doesn't reveal anything, you need to check the string length, or do a hex dump of each to discover non visible character differences.

  5. #5
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,406
    Mentioned
    149 Post(s)
    Tagged
    4 Thread(s)
    Thanks crmalibu. That alert showed me value2 was undefined. And it was undefined because I didn't upload the latest version of the form with the correct input field id...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •