Hi
I’m hoping for a little bit of help. I’m bringing in a CSV file via Javascript/AJAX and then attempting to create an unordered list.
The AJAX bit works just fine, however building the list is proving an issue. Below is the relevant code:
unction makeList() {
if (xmlhttp.readyState==4) {
if (xmlhttp.status==200) {
var tmpArr=xmlhttp.responseText.split('\
');
var out='<ul>';
var tmp;
var val;
var txt;
for (var idx=0;idx<tmpArr.length;idx++) {
tmp=tmpArr[idx].split(',');
txt = tmp[1];
val = tmp[0];
if(txt.charAt(0)=="I") {
out += '<li><a href="#">'+txt+'</a></li>';
}else{
//do nothing. Just in place whilst testing
}
}
out += '</ul>';
document.getElementById('prodMenuItem').innerHTML=out;
}
}
}
As you can see I am attempting to bring out items from the CSV file that begin with “I”. Everytime I do this I get:
txt is undefined
which errors out at the line
if(txt.charAt(0)=="I") {
But bizarrely if I do:
alert(txt);
AFTER the line my debugger says the code breaks at, then all the 'I’s do indeed get alerted out to the screen.
If anyone has any idea whats going on and how to approach fixing this I’d be very grateful