Type error: cannot read property 'rows' of null when deleting a row using javascript - Stack Overflow

I have this javascriptfunction deleteRow(tableID) {try {var table = document.getElementById(collct_tabl

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
Add a ment  | 

1 Answer 1

Reset to default 3

You'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";

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744770276a4592717.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信