Hi all,
I've been trying to create a table dynamically upon the generation of en event using the appendChild method in Javascript. This seems to work fine in Firefox, but not in IE7. There's also no error message from IE. I'm new to these routines. Could someone shed some light on where I could be going wrong? Here's the code:
I've been trying to create a table dynamically upon the generation of en event using the appendChild method in Javascript. This seems to work fine in Firefox, but not in IE7. There's also no error message from IE. I'm new to these routines. Could someone shed some light on where I could be going wrong? Here's the code:
Code:
<html>
<head>
<script type='text/javascript'>
function makeTable()
{
var nTable=document.createElement('table');
nTable.setAttribute('id','myTable');
nTable.setAttribute('border','1');
var nRow1=document.createElement('tr');
var nData11=document.createElement('td');
nData11.setAttribute('colspan','2');
var nCenter11=document.createElement('center');
var nBold=document.createElement('b');
nBold.appendChild(document.createTextNode('Title'));
nCenter11.appendChild(nBold);
nData11.appendChild(nCenter11);
nRow1.appendChild(nData11);
var nRow2=document.createElement('tr');
var nData21=document.createElement('td');
var nCenter21=document.createElement('center');
nCenter21.appendChild(document.createTextNode('21'));
nData21.appendChild(nCenter21);
var nData22=document.createElement('td');
var nCenter22=document.createElement('center');
nCenter22.appendChild(document.createTextNode('22'));
nData22.appendChild(nCenter22);
nRow2.appendChild(nData21);
nRow2.appendChild(nData22);
nTable.appendChild(nRow1);
nTable.appendChild(nRow2);
alert('Almost there !');
try
{
document.getElementById('container').appendChild(nTable);
}
catch (e)
{
alert(e.message);
}
return;
}
</script>
</head>
<body>
<div id='container'>
</div>
<br>
<input type=button value='Go' onclick='makeTable();'>
</body>
</html>
Comment