I have a table that the rows are dynamically added using javascript:
<div class="bg-white p-3" id="IPCRTable">
<div class="hotel pb-4 table-bordered">
<div style="overflow-x:auto;">
<table class="table" id="table" name="table">
<thead>
<tr class="table-active">
<th scope="col" rowspan="2">Output <br>(A)</th>
<th scope="col" rowspan="2">Success Indicators<br>(Targets + Measures)<br>(B)</th>
<th scope="col" rowspan="2">Actual Accomplishments<br>(C)</th>
<th scope="col" colspan="4">Rating<br>(D)
<table class="table table-borderless" id="rating">
<tr>
<td>Q</td>
<td>E</td>
<td>T</td>
<td>A</td>
</tr>
</table>
</th>
<th scope="col" rowspan="2">Remarks<br>(E)</th>
<th scope="col" rowspan="2">Action</th>
</tr>
</thead>
<tbody id = "tbody">
<!-- to be filled by javascript-->
</tbody>
</table>
</div>
</div>
here is the modal that adds values to the row that will be appended onto my table:
</div>
<div class="d-grid gap-2 d-md-flex justify-content-md-end align-items-center">
<button class="btn btn-success btn-sm" role="button" id="addheader" aria-pressed="true" data-bs-toggle="modal" data-bs-target="#addHeader">ADD HEADER</button>
<button class="btn btn-success btn-sm" role="button" id="addtask" data-bs-toggle="modal" data-bs-target="#exampleModal" aria-pressed="true">ADD OUTPUTS/INDICATORS/ACCOMPLISHMENTS</button>
<a href="Create_IPCR.php" class="btn btn-success btn-sm" role="button" aria-pressed="true">ADD SUB-HEADER</a>
</div>
here is the javascript function that adds rows to my table,
function addRows(){
var table = document.getElementById('tbody'),
newRow = table.insertRow(table.length),
cell0 = newRow.insertCell(0),
cell1 = newRow.insertCell(1),
cell2 = newRow.insertCell(2),
cell3 = newRow.insertCell(3),
cell4 = newRow.insertCell(4),
cell5 = newRow.insertCell(5),
cell6 = newRow.insertCell(6),
cell7 = newRow.insertCell(7),
cell8 = newRow.insertCell(8),
outputA = document.getElementById("outputA").value,
indicatorB = document.getElementById("indicatorB").value,
accomplishmentC = document.getElementById("accomplishmentC").value;
cell0.innerHTML = outputA;
cell1.innerHTML = indicatorB;
cell2.innerHTML = accomplishmentC;
cell3.innerHTML;
cell4.innerHTML;
cell5.innerHTML;
cell6.innerHTML;
cell7.innerHTML;
cell8.innerHTML = '<button class="btn btn-success btn-sm" role="button" data-bs-toggle="modal" data-bs-target="#editData" aria-pressed="true" name="tdName" id="editModal"><span class="fas fa-edit"></span></button><a href="#" class="btn btn-info btn-sm" role="button" aria-pressed="true"><span class="fas fa-comment"></span></a> <button class="btn btn-danger btn-sm" role="button" aria-pressed="true" name = "deletebtn" id="deletebtn" onclick= "deleteRow(this)"><span class="fas fa-trash" ></span></button>';
};
as you can see from the function, there is a group of bootstrap buttons on cell8 that are supposed to be able to edit, delete, and add a comment on the row (though im not really sure how to implement that, i will just figure it out next time)
I successfully made the delete button to work, but I’m having trouble making the edit button work. What’s supposed to happen is when it is pressed, a modal would pop up and then it would take the users new value, after hitting the save changes button on the modal, its supposed to edit the data of that certain row without reloading the page.
I know I’m supposed to get the rowIndex of that row… but other than that I’m completely stumped. How can I make this button work?