开发者

Make array out of all checkboxes that were checked?

I have a list of people I want to pull from a database. Next to each one, I have a checkbox, here:

<input type='checkbox' name='check' value='".$rows4['id']."'>

They all have to be the same name for me to be able to check all of them / deselect all of them with javascript:

// HTML
<input type='checkbox' onClick='checkAll(document.confirm_form.check)' name='allChecker'>

// JS
function checkAll(field) {
    if (confirm_form.allChecker.checked == true) {
        for (i = 0; i < field.length; i++) {
            field[i].checked = true ;
        }
    } else {
        for (i = 0; i < field.length; 开发者_如何学编程i++) {
            field[i].checked = false ;
        }
    }
}

So how will I come out with an array of all the ones that were checked? I have this, but it only returns the last one checked!

<?php 
if ($_POST['send_confirm']) {
    $check = $_POST['check'];
    echo "the check: $check";
}
?>

What would my best bet be?

Thanks.


You can use the special syntax name="check[]" on all the checkboxes. Then the values appear as an array when you retrieve them using $_POST

Here is a good article I found, passing-input-arrays-in-php


You can try with form elements array.

<input type='checkbox' name='check[]' value='".$rows4['id']."'>


 $("#formid").find("input:checked").each(function()
 {  
   (this.id).attr('checked',true); 
 }); 

use Jquery method to check and uncheck the checkbox

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜