I have a table with a checkbox. And I wanna do when checkbox is checked, cross out Task and Id. I read about On Change, and i know the css property but i don't know how identify the task and id to crossout
This is my project: Crud PHP
This is my code:
<div class="col-md-8">
<table class="table table-dark table-striped table-hover text-center">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Tasks</th>
<th scope="col">Finished</th>
<th scope="col">Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($tasks as $task):?>
<tr>
<th scope="row"><?php echo $task['Id'] ?></th>
<td><?php echo $task['Task'] ?></td>
<td>
<?php if ($task['Finished'] == 0){ ?>
<div class="form-check">
<input class="form-check-input position-static" type="checkbox" id="checkbox<?php echo $task['Id'] ?>" value="option<?php echo $task['Id'] ?>">
</div>
</td>
<?php }else{ ?>
<div class="form-check">
<input class="form-check-input position-static" type="checkbox" id="checkbox<?php echo $task['Id'] ?>" value="option<?php echo $task['Id'] ?>"checked>
</div>
<?php };?>
<td>
<a class="btn btn-warning mr-2" href="functions/editTask.php?Id=<?php echo $task['Id'] ?>">Edit</a>
<a class="btn btn-danger" href="functions/deleteTask.php?id=<?php echo $task['Id'] ?>">Delete</a></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
I found a code and I tried adapt it but is wrong
function crossOutTask() {
check = document.getElementByTagName("input:checkbox");
if (check.checked) {
$('tr').css('textDecoration','line-through');
} else {
$('tr').css('textDecoration', 'none');
}
}
Thanks