Dear all,
below code snippet insert one row to table & delete one row if its index in more than 11 . Its working Fine in all browser even working in IE but giving Error ,
I think that is Exception "Index or size is negative or greater than allowed ...." i have seen this error in Mozzila error Console.

if(single_record != ''){
                        var record_data = single_record.split("#*#");var no_of_rows1 = document.getElementById(table_id).rows.length;
                        var x = document.getElementById(table_id).insertRow(0);
                       x.style.backgroundColor = tr_Color;// TR bgcolor is set

                       var no_of_rows = document.getElementById(table_id).rows.length;// To find total no. of rows 

                       var g0=x.insertCell(0); g0.align = "center";
                        var g1= x.insertCell(1);g1.align = "center";
                        var g2=x.insertCell(2);g2.align = "center";
                       var g3=x.insertCell(3);g3.align = "center";

                       g0.innerHTML = '<font face="Verdana, Arial, Helvetica, sans-serif" size="1" color = "#000000" >'+record_data[0]+'</font>';
                        g1.innerHTML= '<font face="Verdana, Arial, Helvetica, sans-serif" size="1" color = "#000000" >'+record_data[1]+'</font>';
                         g2.innerHTML= '<font face="Verdana, Arial, Helvetica, sans-serif" size="1" color = "#000000" >'+record_data[2]+'</font>';
                          g3.innerHTML='<font face="Verdana, Arial, Helvetica, sans-serif" size="1" color = "#000000" >'+record_data[3]+'</font>';
                                                                        //alert(no_of_rows+'__Bunti___'+no_of_rows1);
                            if(no_of_rows > 11){ // If dynamically row is added this to maintain per_page row deletion 
                                     for(var m = 10;m<no_of_rows;m++){
                                                        document.getElementById(table_id).deleteRow(m);// HERE MIGHT B THE ERROR
                                          }
                                 }
      }

Recommended Answers

All 2 Replies

for(var m = 10;m<no_of_rows;m++){
  document.getElementById(table_id).deleteRow(m);// HERE MIGHT B THE ERROR

Deleting row m and then incrementing m skips rows (and causes m to exceed the number of rows in the [reduced] table).
One fix is to delete row 10 n times (n=no_of_rows-max); another is to start m at the last row and decrement.
Don't forget that 12 rows are indexed 0..11

Thanks ....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.