String comparison with == operator is legal but it compares the 2
references.
What is your result with string1.equals(string2) ?
On Mon, Sep 8, 2008 at 12:27 PM, Abraham Rodriguez Mota <
[EMAIL PROTECTED]> wrote:
> Hi all,
>
> I am trying to compare two strings but the comparison operator always
> returns false. I printed the values using the alert function and the strings
> are read properly but the result is always false even when they are equal.
> The comparison works when I compare the var values with static strings
> -(i.e: currentId=='c1c2'), but not when comparing the two
> variables-(currentId==elementID). I have tried to cast the values to strings
> and use the localeCompare method but it didn't work. Any help will be
> really appreciated.
>
> function updateConnections(targetElement){
> //Reading custom metadata, name space xxx
> var relation=targetElement.getElementsByTagNameNS(xxx,'rel');
> var elementID;
>
> var currentId=relation.item(0).firstChild.nodeValue;
> var updateRelation=relationsGroup.getElementsByTagName('line');
>
> if(updateRelation.length>0){
>
> for(var i=0;i<updateRelation.length;i++){
>
> elementID=updateRelation.item(i).getAttribute('id');
> //variable's content change
> alert(elementID +" " + currentId+ " ");
> //but this is always false
> alert(elementID == currentId);
>
>
> //Here is the problem
> if(currentId==elementID){
> alert(elementID+currentId);
> }
>
> elementID=' ';
> }
> }
> }
>
> thanks a lot
>
> Abraham
>