I am trying two pare two strings in JavaScript. But I guess there is some problem while paring. It doesn't show the results.
if(ajaxRequest.readyState == 4){
var msg = ajaxRequest.responseText;
var fld = document.getElementById("prtCnt");
if(msg == "false") {
var msg = "This User Name is already taken !!!!";
fld.className = "bp_invalid";
// fld.style.color=green;
fld.innerHTML=msg;
}
Can any body tell me where the problem is? Thanks.
I am trying two pare two strings in JavaScript. But I guess there is some problem while paring. It doesn't show the results.
if(ajaxRequest.readyState == 4){
var msg = ajaxRequest.responseText;
var fld = document.getElementById("prtCnt");
if(msg == "false") {
var msg = "This User Name is already taken !!!!";
fld.className = "bp_invalid";
// fld.style.color=green;
fld.innerHTML=msg;
}
Can any body tell me where the problem is? Thanks.
Share Improve this question edited Mar 3, 2012 at 5:16 dyoo 12k1 gold badge37 silver badges45 bronze badges asked Mar 3, 2012 at 5:03 adeshadesh 8524 gold badges14 silver badges24 bronze badges 3-
2
Did you even check the value of
msg
? – takteek Commented Mar 3, 2012 at 5:07 - with out if condition it shows me false on web page. But with if it fails. – adesh Commented Mar 3, 2012 at 5:09
-
2
You might as well add the following "print" statement to see what value you are receiving in
msg
:alert(msg);
Put that before yourif(msg == 'false')...
test, and amend your question with that additional information. – dyoo Commented Mar 3, 2012 at 5:20
2 Answers
Reset to default 5You might want to check if there's any space before or after the "false" string that you return from the server. You can do it easily with this:
alert('"' + msg + '"');
If there is extra space, you can just do:
msg = msg.trim();
and then do your if statement
Ensure that there is no white space around the word "false" with something like:
if( msg.match(/\s*false\s*/i) )