aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Problem with String compare in JavaScript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Problem with String compare in JavaScript" Watch "Problem with String compare in JavaScript" New topic
Author

Problem with String compare in JavaScript

Rajkumar balakrishnan
Ranch Hand

Joined: May 29, 2008
Posts: 445

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....


Never try to be a hard-worker. Be a smart-worker.
My Blog
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39549
    
  27
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]


Ping & DNS - updated with new look and Ping home screen widget
Rajkumar balakrishnan
Ranch Hand

Joined: May 29, 2008
Posts: 445

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
Marshal

Joined: Mar 22, 2005
Posts: 39549
    
  27
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

Joined: May 29, 2008
Posts: 445

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

Joined: May 29, 2008
Posts: 445

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

Joined: Nov 08, 2001
Posts: 15376
    
    6
Last time I checked, JavaScript does not have a built in String method called equals.

Eric
Rajkumar balakrishnan
Ranch Hand

Joined: May 29, 2008
Posts: 445

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....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with String compare in JavaScript
 
Similar Threads
How to insert at runtime using AJAX
Select element issue
Ajax's response when server is down.
Problem with AJAX in FireFox
Displaying a Greeting message using Ajax