admin管理员组文章数量:1391735
I have this javascript
function deleteRow(tableID)
{
try {
var table = document.getElementById(collct_table_body);
var rowCount = table.rows.length;
for(var i=0; i<rowCount; i++) {
var row = table.rows[i];
var chkbox = row.cells[0].childNodes[0];
if(null != chkbox&& true == chkbox.checked) {
if(rowCount <= 1) {
alert("Cannot delete all the rows.");
break;
}
table.deleteRow(i);
rowCount--;
i--;
}
}
}catch(e) {
alert(e);
}
But when I try to delete a row using this it shows an error "cannot read property 'rows' of null type error"
Is there any error in this javascript Im using?Can some one help me out?
I have this javascript
function deleteRow(tableID)
{
try {
var table = document.getElementById(collct_table_body);
var rowCount = table.rows.length;
for(var i=0; i<rowCount; i++) {
var row = table.rows[i];
var chkbox = row.cells[0].childNodes[0];
if(null != chkbox&& true == chkbox.checked) {
if(rowCount <= 1) {
alert("Cannot delete all the rows.");
break;
}
table.deleteRow(i);
rowCount--;
i--;
}
}
}catch(e) {
alert(e);
}
But when I try to delete a row using this it shows an error "cannot read property 'rows' of null type error"
Is there any error in this javascript Im using?Can some one help me out?
Share Improve this question edited Dec 12, 2013 at 17:22 Tadmas 6,3784 gold badges40 silver badges31 bronze badges asked Dec 12, 2013 at 17:14 user3079558user3079558 2- Instead of editing the question to show [solved], you should accept the answer below to indicate that solved your problem. – Tadmas Commented Dec 12, 2013 at 17:23
- Sorry, I was trying to be more constructive instead of just saying "I rolled back your edit because what you did is against our guidelines." Or just rolling back with no explanation. I didn't intend it to sound as harsh as I can see now it is - my apologies. See also meta.stackexchange./questions/116101/… – Tadmas Commented Dec 12, 2013 at 19:29
1 Answer
Reset to default 3You're missing the quotes
document.getElementById("collct_table_body");
or, may be this is a variable (which I don't see in your code, global var?? we will never know)
var collct_table_body = "someID";
本文标签: Type error cannot read property 39rows39 of null when deleting a row using javascriptStack Overflow
版权声明:本文标题:Type error: cannot read property 'rows' of null when deleting a row using javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744770276a2624297.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论