I need help with my code. How do I add the index number whenever the user clicks the add button and how should I insert text input just like the first row? I am still learning how to use JS. Thank you in advance!
function childrenRow() {
var table = document.getElementById("childTable");
var row = table.insertRow(2);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
var cell3 = row.insertCell(2);
var cell4 = row.insertCell(3);
var cell5 = row.insertCell(4);
}
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous">
<table class="table table-bordered" id="childTable">
<thead class="table-info">
<tr>
<th scope="col">No.</th>
<th scope="col">Name</th>
<th scope="col">School / University </th>
<th scope="col">Year</th>
<th scope="col">Age</th>
<th scope=""></th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">1</th>
<td class="col-sm-4">
<input type="text" name="name" class="form-control" />
</td>
<td>
<input type="text" name="school" class="form-control" />
</td>
<td class="col-sm-2">
<input type="text" name="year" class="form-control" />
</td>
<td class="col-sm-2">
<input type="text" name="age" class="form-control" />
</td>
<td>
<input type="button" class="btn btn-block btn-default" id="addrow" onclick="childrenRow()" value="+" />
</td>
</tr>
</tbody>
</table>