Jon Martin
Jon Martin

Reputation: 3392

Internet Explorer javascript compatibility

I have a simple javascript function to check all checkboxes when a header checkbox is selected.

function SelectAll(id) {       
    var grid = document.getElementById("<%=ui_downlinkGrid.ClientID %>");
    var cell;
    if (grid.rows.length > 0)
    {
        for (i = 0; i < grid.rows.length; i++)
        {
            cell = grid.rows[i].cells[0];
            cell.childNodes[1].checked = document.getElementById(id).checked;
        }
    }
}

I tested this on IE 9 and it works perfectly. However once I got it on Windows Server 2008, it does not work, and the debugger shows this error: Object doesn't support this property or method.

Is this a compatibility issue? How can I solve this?

EDIT: The error is on this line:

cell.childNodes[1].checked = document.getElementById(id).checked

enter image description here

Upvotes: 0

Views: 608

Answers (1)

circusbred
circusbred

Reputation: 1240

childNodes return text nodes as well as elements, its plausible that you are now hitting a textnode, rather than the input you are attempting to access. Use children or getElementsByTagName instead:

The following assumes that there is an element before the <input>:

cell.children[1].checked = document.getElementById(id).checked;

Upvotes: 1

Related Questions