I am trying to add an empty row based on the row that I already have. I have spent an hour looking around and trying different ways but none seem to work. This is what I have so far:
HTML:
<div id="Oretablediv">
<table id="OreTable" border="1">
<tr>
<td>Ore</td>
<td>Amount</td>
<td>Price</td>
<td>Sub Total</td>
<td>Delete?</td>
<td>Add Rows?</td>
</tr>
<tr>
<td>
<select name="Ore">
<option value="value1">Value 1</option>
<option value="value2">Value 2</option>
</select>
</td>
<td><input size=25 type="text" id="Amount" ></td>
<td>Price</td>
<td>SubTotal</td>
<td><input type="button" id="delOrebutton" value="Delete" onclick="deleteRow(this)"/></td>
<td><input type="button" id="addOrebutton" value="Add More Ore" onclick="insRow()"/></td>
</tr>
</table>
Javascript:
function deleteRow(row){
var i=row.parentNode.parentNode.rowIndex;
document.getElementById('OreTable').deleteRow(i);
}
function insRow(){
var row = document.createElement('tr');
var col = document.createElement('td');
var col2 = document.createElement('td');
row.appendChild(col);
row.appendChild(col2);
var table = document.getElementById("OreTable");
table.appendChild(row);
}
I am currently only asking about the insRow() function, if you have suggestions for the delete row please share.
cloneNodeand then fill out the fields after that.