Jump to content

Very Strange Problem


frankp

Recommended Posts

helloI have some problems with an if-statement not working. In this, I discovered that the XML is the problem, because I tried without calling the xmlsheet.However, the alert clearly displays the correct number(so there's no problem with accessing the info in the XML), which may be 0 or may be 3, but in both cases we always end up in the else-place.why is 0 not 0?

	x=xmlDoc.getElementsByTagName(xname);	xcount=x[0].getElementsByTagName(xname.slice(0,1)+"count")[0].childNodes[0].nodeValue;	alert(xcount.valueOf()); //this always displays the right number					   				if(xcount=0){//this is the place I want to be if the xcount is 0	} else {//this is the else-place where I end up anyway	}

Link to comment
Share on other sites

would it need to be if(xcount == 0)?
well, it worked. Thank you. I've never seen this necessary in JavaScript...if I hadn't used the xml it would have worked anyway, so I've kinda though it was not a part of the language. In any case, thank you very much!
Link to comment
Share on other sites

I think the difference is in the use of = vs. ==. Where as = will just set xcount to 0, == will check the value of xcount to that number (0), which in turn seems to fill the conditional nature of if/else statements. With =, I think the code would just interpret it as you just setting the variable, where you want it to base its execution of the next lines of code on the condition of whether or not the if line meets a given condition. In other words, xcount = 0 fulfills itself, thus not setting a condition to be checked for logical operation(s).I think... :)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...