Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: row is undefined

I need help with this JavaScript function I made. It works, but it always alerts me with:

"TypeError: row is undefined"

when I launch it.

Here is my code:

function checkRow(tableID){
        try{
        var table = document.getElementById(tableID);
        var rowCount = table.rows.length;

        for(var i = 1; i <= rowCount; i++){
        var row = table.rows[i];
        var id = row.cells[1].innerHTML;
            if(i != id){
            document.getElementById(tableID).rows[i].cells[1].innerHTML = i;
                }
            }

            }catch(e){
            alert(e);
            }
        }
like image 710
Unowndago Vador Avatar asked Nov 05 '22 02:11

Unowndago Vador


1 Answers

Arrays in JavaScript are indexed starting at zero, not one.

    for(var i = 0; i < rowCount; i++){

should help :-)

edit — oh and similarly, the "id" may need to be row.cells[0].innerHTML ...

like image 50
Pointy Avatar answered Nov 10 '22 05:11

Pointy