I have a table (asp.net gridview) with checkboxes in the first cell of most of the rows. When I click a button I run a function to check that at least one of the checkboxes is checked. An extract of the function is below. It runs perfectly in development. Publish to a server, run the page and click the button and the code just ignores the checkboxes.
var somechecked = false;
var table = document.getElementById('gvRecipients');
for (i = 1; i < table.rows.length; i++)
cell = table.rows[i].cells;
//if (table.rows[i].cells.firstChild && table.rows[i].cells.firstChild.type == 'checkbox' && table.rows[i].cells.firstChild.checked)
if (cell.childNodes.type == "checkbox")
somechecked = true;
if (checkemail(table.rows[i].cells.getElementsByTagName('span').innerHTML) == 'wrong')
alert('somechecked in the loop(' + i + ')' + somechecked);
This particular gridview has a row at the top with a checkall checkbox - so I am ignoring this - so I am looping through the table from 1 not 0.
The second row contains headings and has no checkbox in it.
This code - alert(cell.childNodes.type);
in the loop returns 'undefined' for the first row - which is what I would expect as there are no childNodes in the cell.
In the second row, on the development box, it returns 'checkbox' and the code that checks if the checkbox is ticked runs and sets the variable somechecked to true if it is checked.
But, when the site is published, the code - alert(cell.childNodes.type); returns undefined for every row.
If I have a gridview with 30 rows in and every one of them has a checkbox in the first cell (and nothing else) it still returns 'undefined'.
Works on the development box. Does not work when the site is on a server. What is going on?
Please help, it's driving me nuts and I am about to give up and simply validate on the server. How can this be happening?