0
How can I create a checkbox that selects all others from my page?
I’m using a while loop in php to list the records, and each one has its checkbox next to it. I would like to have a checkbox on the page that, when selected, marked all others, for deletion, edit.. situation similar to Hotmail, Gmail in inbox.
Loop in PHP:
<form action="deleta.php" method="post">
<ul class="lista-posts">
<li class="seleciona"><input type="checkbox" id="checkbox" name="deletar[]" value="<?php echo $row['id']; ?> " /></li>
<li class="titulo"><?php echo '.$row['titulo'].'; ?></li>
</ul>
</form>
Resolved as follows:
HTML
<input type=checkbox name=1>
<input type=checkbox name=2>
<input type=checkbox name=3>
<input type=checkbox name=all>
JAVASCRIPT
document.querySelector("input[name=all]").onclick = function(e) {
var marcar = e.target.checked;
var lista = document.querySelectorAll("input");
for ( var i = 0 ; i < lista.length ; i++ )
lista[i].checked = marcar;
};
if I understand, it’s not with php because it’s a client-side thing. You should do this with javascript.
– Daniel Omine
Excuse me, I was a layman when adding the PHP tag.
– Cobra
no problem. Here’s a simple example to use: http://stackoverflow.com/questions/386281/how-to-implement-select-all-check-box-in-html
– Daniel Omine
Thank you! One very useful example that I found before your reply was: http://jsfiddle.net/fjnw4w3L/6/
– Cobra
Do not duplicate the questions please Thiago.
– Guilherme Nascimento
All right, I’m sorry!
– Cobra