meh meh - 1 year ago 90
Javascript Question

Google Chrome sends an error of undefined cells in Javascript

for (var i = RN; i > 1; i--) {
Credit[i] = document.getElementById("table").rows[i].cells[1].innerHTML;
Grade[i] = document.getElementById("table").rows[i].cells[2].innerHTML;
total += Credit[i];

error:Uncaught TypeError: undefined is not a function

I'm not sure why cells in undefined here.

Answer Source

My guess is you have the number of rows and you are forgetting that index starts at ZERO so you need to subtract one from the length. And you probbaly want to change the i > 1 to zero if you are skipping the first row.

for (var i = RN-1; i > 0; i--) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download