<?php
$con = mysql_connect("localhost","root","");
$db = mysql_select_db("abc");
if(!$db){
echo 'Could Not connect database';
}
$sel = mysql_query("select * from user_registration");
?>


<script type="text/javascript" src="http://code.jquery.com/jquery.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
        $('input[type="checkbox"]').click(function(){

            //how to select multiple checkbox value here??????????


        });
    });
</script>

    <div>
    <?php
    while($row = mysql_fetch_array($sel)){
    ?>
        <label>
        <input type="checkbox" name="<?php echo $row['user_id']; ?>" value="<?php echo $row['user_id']; ?>">
        <?php echo $row['first_name']; ?>
        </label>
     <?php
    }
     ?>
    </div>
   <div class="display"></div>

Hi,

Please find following Javascript functions to select / deselect checkbox using div (This will apply checkboxes in a div)

<script type="text/javascript">
function checkedall(divname) {
    $("#" + divname).find(':checkbox').each(function () {
        $(this).attr('checked', true);
    });
}

function uncheckedall(divname) {
    $("#" + divname).find(':checkbox').each(function () {
        $(this).attr('checked', false);
    });
}
</script>

You can all above functions like

<a href="javascript:void(0);" onclick="javascript:checkedall('div_nave');">Select All</a>

In short you can use following code for single checkbox using Id
$('#checkbox_id').attr('checked', true);

If you have any query, Please let me know.
Thanks,
Ajay

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.