In the main table there are two sub tables are there.when user click addRow button
main row and also subrow should be created.i have written the code but when i click addrow alignment is missing and apart from that mainrow and subrow is not displaying properly.
<html>
<head>
<script>
function addrow(){
theTabs = document.getElementById('main');
newRow = document.createElement('tr');
snonewCell = document.createElement('td');
snonewCell.innerHTML=theTabs.rows.length;
newRow.appendChild(snonewCell );
enonewCell = document.createElement('td');
enonewCell.innerHTML="<input type='text'>";
newRow.appendChild(enonewCell );
enamenewCell = document.createElement('td');
enamenewCell.innerHTML="<input type='text'>";
newRow.appendChild(enamenewCell );
alert(theTabs.rows.length)
document.getElementById('sub').rows[theTabs.rows.length-1].appendChild(newRow);
//sub table
newRow1 = document.createElement('tr');
subsnonewCell = document.createElement('td');
subsnonewCell.innerHTML=theTabs.rows.length;
newRow.appendChild(subsnonewCell );
subpartynewCell = document.createElement('td');
subpartynewCell.innerHTML="<input type='text'>";
newRow1.appendChild( subpartynewCell );
document.getElementById('main').insertBefore(newRow1,newRow);
}
</script>
</head>
<body>
<table>
<tr>
<td>
<table border="1" id="main">
<tr>
<td>
SNO
</td>
<td>
EMPNO
</td>
<td>
EName
</td>
<td>
</td>
</tr>
<tr>
<td>
1
</td>
<td>
<input type='text'>
</td>
<td>
<input type='text'>
</td>
<td>
<input type='button' value='add11' onclick="addrow()">
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table border="1" id="sub">
<tr>
<td>
</td>
<td>
Sno
</td>
<td>
Party
</td>
</tr>
<tr>
<td>
</td>
<td>
1
</td>
<td>
<input type='text'>
</td>
<td>
<input type='button' value='add'>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>