I have written a code to add a new row dynamically on a click of a button. There are 5 columns.
The third column contain Two radio buttons, and on click of each radio button, new options appear. This Works Fine for the first row, but as soon as I click on the button to generate a new row problems start.
When I click on the radio button of the second row, options appear on the first row. Instead I want them to appear in that specific column.
Here is my code for adding a row
function addRow(tableID) {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
var colCount = table.rows[0].cells.length;
for(var i=0; i<colCount; i++) {
var newcell = row.insertCell(i);
newcell.innerHTML = table.rows[1].cells[i].innerHTML;
}
}
And this is my table
<TABLE id="dataTable" border="1">
<td><input type="text" id=1 /></td>
<td><input type="text" id=2 /></td>
<td>
<input type="radio" name="radio1" value="1" onClick="toggleDisplay('mydiv','mydiv1');">Own
<input type="radio" name="radio2" value="1" onClick="toggleDisplay1('mydiv','mydiv1');">Contractor
<div id="mydiv" style="display:none;">
<input type="radio" name="Wage" value="Wage">Wage Board
<input type="radio" name="Staff" value="Staff">Staff
</div>
<div id="mydiv1" style="display:none;">
Name Of Contractor: <input type="text" name = "text" >
<input type="radio" name="No" >No of Workmen
</div>
</td>
<td><input type="text" id=5 /></td>
<td><input type="text" id=4 /></td>
</tr>
</TABLE>
<INPUT type="button" value="Add Row" onclick="addRow('dataTable')" />
Please help me out on this one as soon as possible. I think the problem is with unique ids.
$("#" + tableID).append($("#" + tableID + " tbody tr:first").clone());. And learn what structure table have.<tr>start tag, your table technically doesn't contain any rows. Anyway, if you already know the problem is with duplicate ids, what have you tried to make sure the ids are unique?