I have two functions addrow() and deleterow(i)
The delete row function works for the first row on the table and then will not delete any others.
The addrow function works everytime.
Here is my code. Any help would be greatly appreciated..
The delete row function works for the first row on the table and then will not delete any others.
The addrow function works everytime.
Here is my code. Any help would be greatly appreciated..
Code:
<script language="javascript">
function deleteRow(i)
{
document.getElementById('table1').deleteRow(i)
}
function addRow()
{
var tbody = document.getElementById("table1").getElementsByTagName("tbody")[0];
var row = document.createElement("TR");
var cell1 = document.createElement("TD");
var inp1 = document.createElement("INPUT");
inp1.setAttribute("type","text");
inp1.setAttribute("value","");
cell1.appendChild(inp1);
var cell2 = document.createElement("TD");
var inp2 = document.createElement("INPUT");
inp2.setAttribute("type","text");
inp2.setAttribute("value","");
cell2.appendChild(inp2);
var cell3 = document.createElement("TD");
var inp3 = document.createElement("INPUT");
inp3.setAttribute("type","text");
inp3.setAttribute("value","");
cell3.appendChild(inp3);
var cell4 = document.createElement("TD");
var inp4 = document.createElement("INPUT");
inp4.setAttribute("type","button");
inp4.setAttribute("value","Delete");
inp4.setAttribute("onClick", "deleteRow(this.parentNode.parentNode.rowindex)");
cell4.appendChild(inp4);
row.appendChild(cell1);
row.appendChild(cell2);
row.appendChild(cell3);
row.appendChild(cell4);
tbody.appendChild(row);
//alert(row.innerHTML);
}
</script>
Code:
<table id="table1">
<tbody>
<tr>
<td><input type="text" value=""></td>
<td><input type="text" value="" width="10"></td>
<td><input type="text" value="" width="10"></td>
<td><input type="button" value="Delete" onclick="deleteRow(this.parentNode.parentNode.rowIndex)"></td>
</tr>
</tbody>
</table>
<input type="button" value="Insert Row" onClick="addRow();">