I have a table that is dynamically created. Each table row
has onclick
implemented.
Here is my piece of code for creating table rows:
foreach ($db_response as $row) {
echo '<tr onclick="open_edit_task_modal(this)" id="row-' . $row['id'] . '" ';
if (Status::is_in_progress(intval($row['status']))) {
echo 'class="table-warning"';
} else if (Status::is_finished(intval($row['status']))) {
echo 'class="table-success"';
}
echo '>';
echo '<th scope="row">' . $row['id'] . '</th>';
echo '<td>' . $row['street'] . '</td>';
echo '<td>' . $row['phone'] . '</td>';
echo '<td>' . format_date($row['date']) . '</td>';
echo '<td>' . $row['price'] . '</td>';
echo '<td>' . $row['comment'] . '</td>';
echo '<td>' . $row['operator'] . '</td>';
echo '<td>' . Status::get_status_name_by_id($row['status']) . ' / ';
if (Status::is_unassigned(intval($row['status']))) {
echo '<button type="button" class="btn btn-primary btn-sm" onclick="update_task_status(this)">Accept</button>';
} else if (Status::is_in_progress(intval($row['status']))) {
$db_response = DB::select_user_by_id(intval($row['worker_id']));
if ($db_response['name'] === $_SESSION['name'] && $db_response['surname'] === $_SESSION['surname']) {
echo '<button type="button" class="btn btn-success btn-sm" onclick="update_task_status(this)">Finish</button>';
} else {
echo $db_response['name'] . ' ' . $db_response['surname'];
}
}
echo '</td>';
...
As you can see my <tr>
has onclick
which is called open_edit_task_modal()
. And my button
that is positioned on that same <tr>
has onclick
which is called update_task_status()
.
Everything works with button clicking and row clicking, no complaints there.
The only problem that I have is that when I click button
the <tr>
is also clicked so I am getting both onclick
s triggered.
I would like to avoid that behavior. I currently have no idea how I can achieve such thing, please help.