views:

6568

answers:

4
function DeleteData(ID)
{
 var ctrlId=ID.id;

 var divcontents=document.getElementById(ctrlId).innerHTML;
 var tabid=ctrlId.replace(/div/,'tab');
 var tabcontents=document.getElementById(tabid).innerHTML;
 alert(document.getElementById(tabid).innerHTML);
 document.getElementById(tabid).innerHTML="<TBody><tr><td></td></tr><tr><td></td></tr><tr><td></td></tr></TBody>";
 document.getElementById(ctrlId).innerHTML='';

}

I am trying to replace the Table with empty table but

document.getElementById(tabid).innerHTML="<TBody><tr><td></td></tr><tr><td></td></tr><tr><td></td></tr></TBody>";

this line is causing Unknown Runtime Error

+3  A: 

You can't set value to a table's innerHTML, you should access to child cells or rows and change them like that :

document.getElementById(tabid).rows[0].cells.innerHTML = 'blah blah';

For more info/example : Table, TableHeader, TableRow, TableData Objects

Canavar
actually, in IE8 it's document.getElementById(tabid).rows[0].cells[0].innerHTML = 'blah blah';
Quandary
A: 

It works fine in Firefox

A: 

This is not a Big issue, since i faced same problem few days ago and the reason this error occurs in ie is that - There exists an error in our html format or you are using an element other than to replace innerHTML ie use only, dont use tables,divs to replace innerHTML.

  • SwapnilK