Adding a Select All Checkbox

select all checkbox jquery
select all checkbox javascript w3schools
select all checkbox javascript example
select all checkbox example
javascript select all checkboxes in table
how to select all checked checkboxes jquery
javascript check all checkboxes on page
select all checkbox javascript by id

I want to add a check/uncheck all button for this script:

php:

require_once('includes/commons.php');

$query_get_addresses = 'SELECT * FROM user ORDER BY first_name ASC, last_name ASC';
$result_get_addresses = mysql_query($query_get_addresses);
$addresses_count = mysql_num_rows($result_get_addresses);

?>

script:

<script>
$(document).ready(function() {
    // initialize
    var recipient = $('input[name=recipient]').val();
    var recipient_array = new Array();
    if(recipient != '') {
        recipient_array = recipient.split(',');
        for(var i = 0; i < recipient_array.length; i++) {
            recipient_array[i] = $.trim(recipient_array[i]);

            if(recipient_array[i] == '')
                recipient_array.splice(i, 1);
        }

        $('input[type=checkbox]').each(function() {
            if($.inArray(this.value, recipient_array) >= 0) {
                $(this).attr('checked', true);
            }
        });
    }
    // add and/or remove
    $('input[type=checkbox]').click(function() {
        var recipient_list = '';

        $('input[type=checkbox]').each(function() {
            var index = $.inArray(this.value, recipient_array);
            if(this.checked) {
                if(index < 0)
                    recipient_array.push(this.value);
            }
            else {
                if(index >= 0) {
                    recipient_array.splice(index, 1);
                }
            }
        });

        $('input[name=recipient]').val(recipient_array);
    });
});
</script>

html:

<h2>Choose recipient</h2>
<div><?php

if($addresses_count > 0) {

    ?><form name="select-recipient-form"><ul><?php

        while($row_get_addresses = mysql_fetch_assoc($result_get_addresses)) {
            $row_get_addresses = unsanitize($row_get_addresses);

            ?><li><input type="checkbox" name="recipient[]" id="recipient-1" value="<?php echo $row_get_addresses['recipient']; ?>" /><label for="recipient-1"><?php echo $row_get_addresses['first_name'].' '.$row_get_addresses['last_name'].' &lt;'.$row_get_addresses['recipient'].'&gt;'; ?></label></li><?php
        }

    ?></ul>
    </form><br /><?php

} else {

    ?><p>You don't have any contacts.</p><?php
}

?>
</div>

I have tried to follow some guides. Like this one for example but I can't get it to work. Any idea how I can achieve this? Thanks

this worked for me:

    <script type="text/javascript"> 
$('#form1').ready(function(){
    $('.gumb:button').toggle(function(){
        $('.tocheck ').attr('checked','checked');
        $(this).val('uncheck all')
    },function(){
        $('.tocheck ').removeAttr('checked');
        $(this).val('check all');        
    })
})

</script>

<input type="button" class="gumb" value="check all" />
<input name="checkbox[]" class="tocheck" type="checkbox" value="<?php echo $rows['member_id'] ?>" />

Select all checkboxes using JavaScript - JavaScript, Do you have any idea to make this work on IE too? <script language="JavaScript" > function selectAll(source) { checkboxes = document. Add the Select All Checkbox To do this, we will modify the form on our Index page by adding a <div> element containing our global checkbox, which we will name " checkall ", and then also wrap our HTML table in a div named " checkboxes " that we can then manipulate using JQuery. Add Div Elements to HTML Form on the Index Page Hide Shrink Copy Code

Add a class to you check boxes and then use:

<form ...>
    <input type="checkbox" class="check-class" ... />
    ...
    <button type="button" class="check-all">Check All</button>
</form>

<script type="text/javascript">
    (function() {
        var checked = false;
        $('button.check-all').click(function() {
            checked = !checked;
            $('.checkbox-class').prop('checked', checked); // jQuery 1.6+
            if (checked) $(this).text('Uncheck All');
            else $(this).text('Check All);
        });
    })();
</script>

How to implement “select all” check box in HTML with JavaScript , JS. document. getElementById('select-all'). onclick = function() { var checkboxes = document. querySelectorAll('input[type="checkbox"]'); for (var checkbox of checkboxes) { checkbox. checked = this. checked; } Adding a Select All or Cancel All check-box column to tables By default, table footers contain Select All and Deselect All buttons, which enable users to select all the rows in a table and to cancel all their selections in a table (see the following figure).

<span><input type="checkbox" class="checkall" />check all</span>

Add a class to all your checkboxes except the check all check box

<input type="checkbox" class="tocheck ... />
    ...
    ....

$(document).ready(function(){
$('.checkall').click(function() {
    $('.tocheck ').attr('checked', true); 
});
});

JavaScript, JavaScript code to select/unselect all checkboxes, how to check/uncheck all checkboxes using JavaScript function. The “Select all” checkbox have an id #select_all and items checkboxes have a checkbox class. When checkbox with #select_all id is clicked, we will check whether it is checked or not. If #select_all is checked, loop through each checkbox with class checkbox and check all the checkboxes. Otherwise uncheck all the checkboxes.

If following is the HTML <input class="checkbox-class" type="checkbox" value="1" /><input class="checkbox-class" type="checkbox" value="2" /> <input class="checkbox-class" type="checkbox" value="3" /> <input type="button" id="clickit" value="Check All" />

JS will do the job

$("#clickit").click(function() {
    if ($(this).val() == 'Check All') {
        $('.checkbox-class').attr('checked', 'checked');
        $(this).val('Uncheck All');
    } else {
        $('.checkbox-class').removeAttr('checked');
        $(this).val('Check All');
    }

});

How to Check and uncheck all using jQuery and JavaScript, If checkbox checked state is TRUE then loop through all options of the select element and set its selected attribute to true . Perform its opposite if the checkbox � Adding 'Select All' button in standard ALV toolbar for selecting all checkboxes Hi All, Many of us must have faced the problem of adding an extra button to the existing standard toolbar of ALV.In this requirement ALV is displayed with Checkboxes.Two additional buttons have been added one for selecting all and another for deselecting all checkboxes.

This code works fine with me

Jquery

<script type="text/javascript">
$(document).ready(function(){ 
$("#select_all").change(function(){
  $(".checkbox_class").prop("checked", $(this).prop("checked"));
  });
});
</script>

you only need to add class checkbox_class to all checkbox

HTML

<input type="checkbox" id="selecctall">

<input class="checkbox_class" name="recipient[]" value="'.$recipientId.'" type="checkbox" />

Easy and simple :D

How to Select / Deselect All Checkboxes using jQuery – Sanwebe, If you are looking for a quick jQuery snippet that toggles multiple check-boxes checked status simply by clicking "Select All" checkbox (like in� Right click on a checkbox and click on “Format Control”. A dialog box pops up, in the dialog box, click on cell link and then select an empty cell to link the checkbox. Repeat the above step to all the CheckBoxes. In order to identify the linked cells of the CheckBoxes easily, link it to the adjacent cell.

Should a "Select all" checkbox become selected if all checkboxes , The answer is a big 'Yes'. If the user is selecting all the checkboxes individually and once all the items have checked the select all checkbox should also be� This is what this will do, for instance if you have 5 checkboxes, and you click check all,it check all, now if you uncheck all the checkbox probably by clicking each 5 checkboxs, by the time you uncheck the last checkbox, the select all checkbox also gets unchecked

Select All Checkboxes With A Single Checkbox, To select all checkboxes of a worksheet by using a single master checkbox checking, please do with following steps: 1. First, you can add a checkbox, and name� ASP.NET MVC: Add a Select All Checkbox to a Checklist Table Using JQuery Often, we find we need to present our users with a list of items in a table or list, with checkboxes such that the user can select one or more items from the list for additional processing.

How to select all checkboxes using a single checkbox in Excel?, This is another method to insert a checkbox, you can use following VBA code. ActiveSheet.CheckBoxes.Add(left, Right, Height, Width).Select ActiveSheet.CheckBoxes.Add(80, 40, 72, 72).Select. Using above method is only helpful when you exactly know about the place to insert and size of the checkbox. Learn more about this method from here.

Comments
  • please note that the "id" attribute of the checkbox should be distinct.
  • stackoverflow.com/questions/1880313/…
  • for jQuery<1.6 use $('.checkbox-class').attr('checked', 'checked');
  • @Mithun actually, it should be $('.checkbox-class').attr('checked', 'checked');
  • Thanks, this worked great. But how about an uncheck button. In an example on this page link they combined the check/uncheck button by using only one button.
  • you can add a check to see whether atleast one of the checkbox is checked if true then fire $('.checkbox-class').removeAttr('checked'); else fire $('.checkbox-class').attr('checked', 'checked');
  • you can do that check by this code if ($('.checkbox-class:checked').length) { $('.checkbox-class').removeAttr('checked'); } else { $('.checkbox-class').attr('checked', 'checked'); }
  • Hi @coolguy.. this is working fine to select the checkboxes, but not working to deselect.. i even tried with removeAttr, but its not working.. do u have any solution for this ?