I have a code which dynamically add html table columns. And these new columns have 3 radios. And I want to select a single radio out of these 3 in each rows.
I am trying to find out the table row index so that I can add this to the radio id. But getting value undefined .
https://jsfiddle.net/jjayaraman/evo6kx0k/
Problem : 'Coz of this all radio has same ID and I can select only one of all the radios... not one for each row..
Here is my code
$(document)
.ready(
function() {
$("#addBtn")
.click(
function() {
$("#myTable thead tr")
.append(
'<th colspan="3">New Header</th>')
$('#myTable tbody tr')
.append(
'<td><input type="radio" name="interActivity' + $('#myTable tr').rowIndex + ' value="Y"></td><td><input type="radio" name="interActivity' + $('#myTable tr').rowIndex + ' value="N"></td><td><input type="radio" name="interActivity' + $('#myTable tr').rowIndex + ' value="NA">')
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<form>
<table border="1" id="myTable">
<thead>
<tr>
<th>Heading1</th>
<th>Heading2</th>
</tr>
</thead>
<tbody>
<tr>
<td>R1 Column1</td>
<td>R1 Column2</td>
</tr>
<tr>
<td>R2 Column1</td>
<td>R2 Column2</td>
</tr>
<tr>
<td>R3 Column1</td>
<td>R3 Column2</td>
</tr>
</tbody>
</table>
<br>
<input id="addBtn" type="button" value="Add column">
</form>