JavaScript, jQuery, XML - if statement not executing for unknown reason
Posted
by Jack Roscoe
on Stack Overflow
See other posts from Stack Overflow
or by Jack Roscoe
Published on 2010-06-03T13:34:01Z
Indexed on
2010/06/03
13:34 UTC
Read the original article
Hit count: 215
Hi,
I have a 'for' loop which extracts data from an XML document and adds it into some JavaScript objects, each time the loop executes I want it to run a certain function depending on the value of the attribute 'typ' which is being retrieved from the xml.
Currently, the data from the XML is successfully being parsed, which is proven by the first 'alert' you can see which produces the correct value.
However, neither of the 'alert' lines in the 'if' statement lower down are being executed and as a result I cannot test the 'ctyp3' function which is supposed to be called.
Where have I gone wrong?
for (j=0; j<arrayIds.length; j++)
{
$(xml).find("C[ID='" + arrayIds[j] + "']").each(function(){
// pass values
questions[j] = {
typ: $(this).attr('typ'),
width: $(this).find("I").attr('wid'),
height: $(this).find("I").attr('hei'),
x: $(this).find("I").attr('x'),
y: $(this).find("I").attr('x'),
baC: $(this).find("I").attr('baC'),
boC: $(this).find("I").attr('boC'),
boW: $(this).find("I").attr('boW')
}
alert($(this).attr('typ'));
if ($(this).attr('typ') == '3')
{
ctyp3(x,y,width,height,baC);
alert('pass');
} else {
// Add here
alert('fail');
}
});
}
© Stack Overflow or respective owner