function updateStrandDataOnPage(strands, cableID){
console.log(strands);
var tubesOnPage = document.getElementsByClassName("tube");
console.log(tubesOnPage);
if(strands.length != 0){
for(var i=0; i<tubesOnPage.length; i++){
tubesOnPage[i].name = strands[i].tube_id;
tubesOnPage[i].value = strands[i].num_of_strands;
// Make call to server to get individual strand information
var xhr = new XMLHttpRequest();
var xhrURL = "/strand/strandInfo/" + strands[i].tube_id;
xhr.open('GET', xhrURL, true);
// xhr.responseType = 'json';
xhr.onreadystatechange = function(){
if(this.readyState == 4 && this.status == 200){
console.log(xhr.response);
var table = makeTable()
console.log(colors); // ===== remove this
///// PROBLEM HERE //////
for(var j=0; j<strands[i].num_of_strands; j++){
addRows(table, strands[i].tube_id, colors);
}
///// PROBLEM HERE ///////
tubesOnPage[i].parentNode.parentNode.appendChild(table);
}
if(this.status != 200){
console.log(xhr.response, this.status);
}
}
xhr.send();
}
}
else{
for(var i=0; i<tubesOnPage.length; i++){
tubesOnPage[i].value = 0;
}
}
}
Here when I try to access DOM with i which is defined in the for loop above it gives me an error: "cannot read property of undefined ". As far as I know scope is inherited if a function is defined inside a function.
May be I am missing a scope concept!