I have a jsp page in which rows are created dynamically to a table using java script. It is working fine in all the browsers except IE. In IE it is showing the error Unknown
This error shows up, because several elements' innerHTML
property, including are read-only [source] (Tested in IE 6-8). To solve this issue, the best way is to use the insertCell
method:
An universal "lazy" method: (demo: http://jsfiddle.net/VLjhW/2/)
// Variables mystring2, rowCount and table as defined in the question.
var tmp = document.createElement('div'); // <-- Placeholder
tmp.innerHTML = '
';
var row = tmp.firstChild.rows[0]; // <-- Created "real" row
var newrow = table.insertRow(table.rows.length); // <-- New dummy row
newrow.parentNode.replaceChild(row, newrow); // <-- Replace dummy with real row
' + mystring2 + '
Another method:
Demo: http://jsfiddle.net/VLjhW/
// Array of innerHTML properties for each cell
var cells = ['
Type
',
'',
'',
'Description
',
''];
// Array of `class=` attributes for each cell
var cellClasses = ['formlabel', 'formfield', 'formgap', 'formlabel', 'formfield'];
var table = document.getElementById('t1'); // <-- table
var tr = table.insertRow(table.rows.length-1); // <-- Last row
for (var i=0; i