Jump to content

Very Strange Problem


frankp
 Share

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

Edited by thescientist
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...