• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with String compare in JavaScript

 
Rajkumar balakrishnan
Ranch Hand
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK.... Here when i try to execute this code it wont run... I dont know what's wrong with this..
function stateChanged()
{
if (xmlHttp.readyState==4 && xmlHttp.status==200)
{
var xx = xmlHttp.responseText;
if(xx.equals("GTC"))
document.getElementById("GTC").selected=true;
}
}


But when i change the code like below , it will work,,, But obviously i need that if loop inorder to display the results dynamically
function stateChanged()
{
if (xmlHttp.readyState==4 && xmlHttp.status==200)
{
var xx = xmlHttp.responseText;
document.getElementById("GTC").selected=true;
}
}


Please help me ranchers....
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It sounds like the condition is not true because "responseText" does not actually have the value "GTC"; what value does it have?

[pedantic mode]"If" is not a "loop", it's a "switch" or a "condition".[/pedantic mode]
 
Rajkumar balakrishnan
Ranch Hand
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ulf Dittmer:
It sounds like the condition is not true because "responseText" does not actually have the value "GTC"; what value does it have?

[pedantic mode]"If" is not a "loop", it's a "switch" or a "condition".[/pedantic mode]


Of course the responseText has the value of GTC... I confirmed it by print it using an alert statement...

Thanks for correcting me...
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you also made sure that is no leading or trailing white space, line breaks or similar?

Actually, I just notice that you're using the "equals" method. I think that tests for object equality, not string equality. Try the "==" operator instead.
 
Rajkumar balakrishnan
Ranch Hand
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ulf Dittmer:
Have you also made sure that is no leading or trailing white space, line breaks or similar?

Actually, I just notice that you're using the "equals" method. I think that tests for object equality, not string equality. Try the "==" operator instead.


I tried the == before equals and it wont works......

And i checked the white space and etc.... So have i use trim to cut the white spaces..
 
Rajkumar balakrishnan
Ranch Hand
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, there is a series of white spaces are there.. After i trim them, it works now... Thanks for the hint and help Ulf....
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Last time I checked, JavaScript does not have a built in String method called equals.

Eric
 
Rajkumar balakrishnan
Ranch Hand
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Eric Pascarello:
Last time I checked, JavaScript does not have a built in String method called equals.

Eric


Yes, i achieve it with == operator.. Thanks for the info....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic