2
Good people, I have the following code, and he was supposed to select all the values inside the foreach, but instead of doing it just selects the first value..
I tried to make a test of Submit that deletes the scenes only appear when you click on the checkboxes, but the same thing happened, only appeared if you selected the first one. But if you selected the first one and a few more, it would erase anyway, but only appear if the first one was selected..
<form action="" method="post">
<? foreach($itens as $myrow){ ?>
<a href="pagina.php?ID=<? echo $myrow['ID']; ?>"><? echo $myrow['Title']; ?></a>
<? echo $myrow['GDate']; ?>
?>
<? echo $myrow['Hour']; ?>
<div class="dashed-line"></div>
<input name="selector[]" id="testecb" type="checkbox" value="<?php echo $myrow['ID']; ?>" />
</div>
</div>
<?}?>
<input type="button" id="selectall-game-button" label="check all" value="Selecionar tudo"
><input type="submit" id="delete-game-button" value="Eliminar" />
<?
****************** AQUI ESTA A ACÇÃO QUE DELETA.. **************
}
} ?>
JS:
$('#selectall-game-button').click(function(){
var chk = $(this).click('checked')?true:false;
$('#testecb').attr('checked',chk);
});
Does anyone hate why this happens? : ss
$(this).click('checked')?true:false;
should be.attr()
instead of.click()
...– Sergio
You could actually simplify to
$('#testecb').attr('checked', this.checked);
only.– Sergio
@Sergio could, but that wouldn’t change the checkbox status at all :)
– bfavaretto
Yes, because I want you to select everything when I click the button ..
– thecreator
Start by giving a different ID for each checkbox, you cannot repeat Ids in HTML. If you want, you can also put the same class on all to select more easily in jQuery (but this doesn’t eliminate the need for unique Ids).
– bfavaretto