I have a table of products ordered by the value of the last column of each row. I want that when I click on an input, the corresponding checkbox change directly to selected. In this way, when I click on the Save button, only the selected products will be managed to update in the database.
The original code has too many things that are not related to the question, so I have reduced it to this:
var c = 10;
var count = 1;
pageList.forEach(element => {
document.getElementById("tabla_variantes").innerHTML+=`
<tr style="background: white;">
<th class="check_col" scope="row" style="padding: 0px; text-align: center; vertical-align: middle;">
<input type="checkbox" value="${element.numero}" id="row${count}" name="row-check-pro">
</th>
<td> //image </td>
<td> //product number </td>
<td> //product name </td>
<td> //product reference </td>
<td> //product price </td>
<td> //product stock </td>
<td style="text-align:center; vertical-align: middle; padding: 8px 18px;">
<input type="text" class="form-control text-end" id="posicion${element.numero}" value="${c}">
</td>
</tr>
`;
document.getElementById(`posicion${element.numero}`).addEventListener('input', (evt) => {
console.log('run'); // Do something
document.getElementById("row"+count).checked = true;
});
++count;
c += 10;
if (c > list.length*10) c = 10;
});
As you can see I have tried to add a listener to each input, but nothing is showing on the console.