I have two functions to add and remove table rows that contain a form input element. They both work fine, but I have a problem in that I need to show a Remove button input only on subsequently created table rows. My two function are as as follows:
function addRow(table_id){
var clone;
var rows=document.getElementById(table_id).getElementsByTagName('tr');
var index=rows.length;
var tbo=document.getElementById(table_id).getElementsByTagName('tbody')[0];
clone=rows[index-1].cloneNode(true);
tbo.appendChild(clone);
}
function delRow(table_id,button){
var row = button.parentNode.parentNode;
var tbo = document.getElementById(table_id).getElementsByTagName('tbody')[0];
tbo.removeChild(row);
}
and the html content is:
<form>
<table id="mytab">
<tr>
<td>Upload File <input type="file" name="uploadfile[]" onchange="addRow('mytab')" /> <input name="del_row" type="button" value="Remove Row" onclick="delRow('mytab',this)"/></td>
</tr>
</table>
</form>
I am by no means a Javascript expert - more of a newbie - so I'm struggling to come up with a solution.