If i call the tableID in the following js code in a loop since the total table number is dynamic, it gives error: document.getElementById(tableID).rows has no properties.
In the html code, there is matching table1, table2, table3.... if i hardcode it, it works. But i need to put it in a loop, can anyone give me a help? Thanks!
count = 3; //set 3 for example
for (i = 1; i<=count; i++) {
tableID = 'table' + i;
x = document.getElementById(tableID).rows[0].cells[0].innerHTML;
//hardcode the id works, but i really need a loop
//x = document.getElementById("table1").rows[0].cells[0].innerHTML;
alert(x);
}
In the html code, there is matching table1, table2, table3.... if i hardcode it, it works. But i need to put it in a loop, can anyone give me a help? Thanks!
count = 3; //set 3 for example
for (i = 1; i<=count; i++) {
tableID = 'table' + i;
x = document.getElementById(tableID).rows[0].cells[0].innerHTML;
//hardcode the id works, but i really need a loop
//x = document.getElementById("table1").rows[0].cells[0].innerHTML;
alert(x);
}