Value compare problem

I have this script:


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:


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? :goof:

Take a good look at this line:


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

More specifically “.my_form #value2–remove-the-space-here–:slight_smile:

Ok, I got rid of that space, but it makes no difference. Still the same result.


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.

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… :blush: