Hi, I have foreach
in a table that lists several checkboxes
. I need to do a jquery
function that by clicking on the checkbox of <th>
% with_% the checkboxes of the next selecione todos
.
Look at my code:
foreach ($controllersActions as $acaoControlador) {
if ($controlador != $controladorAtual) {
$controlador = $controladorAtual;
?>
<tr>
<th colspan="2">
<?php
echo $this->Form->checkbox('all', [
'hiddenField' => false,
'class' => 'all',
]);
?>
<?= Inflector::humanize($controladorAtual) ?>
</th>
</tr>
<?php
}
?>
<tr>
<td style="padding-left: 20px; width: 10px;">
<?=
$this->Form->checkbox('permissoes[]', [
'hiddenField' => false,
'value' => $acaoControlador,
marcado($entidade, $acaoControlador)
]);
?>
</td>
<td><?= Inflector::humanize($acaoAtual); ?></td>
</tr>
<?php }; ?>
Above is the list of my checkboxes
Below is my jquery function:
$('.all').on('click', function(e){
$this = this;
$.each($(this).children('tr td').find('checkbox'), function(i, item){
alert('oi');
$(item).prop('checked', $this.checked);
});
});
<?= Inflector::humanize($controladorAtual) ?>
</th>
</tr>
An image of the checks on the screen.
Hereistherenderedhtml.
Butclickingthecheckboxthattriggersthisfunction,nothinghappens.Iremovedthejquerycodefromthisexample: link
Can anyone help me?