How to select all checkbox in Codeigniter

You can easily select all checkboxes in Codeigniter by clicking the particular checkbox. On click, we can find if the checkbox is Checked (return true) then we can Checked all other checkboxes and if the checkbox is not checked (return false) then we can uncheck all the other checkboxes.

Answers 1
  • Select all checkboxes on click a checkbox using jQuery

    <!-- JQuery script to check and uncheck checkboxes -->
    $('#selectAll').click(function (e) {
        $(this).closest('table').find('td input:checkbox').prop('checked', this.checked);
    var $checkboxes = $('.checkbox-item');
        var checkboxesLength = $checkboxes.length;
        var checkedCheckboxesLength = $checkboxes.filter(':checked').length;
        if(checkboxesLength == checkedCheckboxesLength) {
            $('#selectAll').prop('checked', true);
            $('#selectAll').prop('checked', false);
    <!-- Html page with checkboxes -->
    <!DOCTYPE html>
    <html lang="en">
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <!-- jQuery -->
        <script src="" integrity="sha256-H+K7U5CnXl1h5ywQfKtSj8PCmoN9aaq30gDh27Xc0jk=" crossorigin="anonymous"></script>
        <title>Checkboxes in table </title>
                <th> <input type="checkbox" id="selectAll" /> Select All </th>
                <th>First Name</th>
                <th>Last Name</th>
                <th>Mobile No.</th>
                <td> <input type="checkbox" class="checkbox-item" id="1"/> Checkbox 1 </td>
                <td>[email protected]</td>
                <td><input type="checkbox" class="checkbox-item" id="2"/> checkbox 2 </td>
                <td>[email protected]</td>
                <td>+44 1632 960733 </td>

    We have used jQuery to checked all checkboxes on the clicked checkbox (select all). On click checkbox, if the value is true then we checked all the checkboxes and if the value is false then we unchecked all the checkboxes.

    Note: You have to use jQuery in HTML.

  • Back to code snippet queries related codeIgniter