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);
            }
        }
                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 ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With