How to select all checkbox in Codeigniter

Created at 19-May-2021 , By samar

How to select all checkbox in Codeigniter

In this session, we are going to try to solve the "How to select all checkbox in Codeigniter" puzzle by using the computer language.

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.
  • Select all checkboxes on click a checkbox using jQuery

    <!-- JQuery script to check and uncheck checkboxes -->
    <script>
    $('#selectAll').click(function (e) {
        $(this).closest('table').find('td input:checkbox').prop('checked', this.checked);
    });
    
    var $checkboxes = $('.checkbox-item');
    $('.checkbox-item').change(function(){
        var checkboxesLength = $checkboxes.length;
        var checkedCheckboxesLength = $checkboxes.filter(':checked').length;
        if(checkboxesLength == checkedCheckboxesLength) {
            $('#selectAll').prop('checked', true);
        }else{
            $('#selectAll').prop('checked', false);
        }
    });
    </script>
    
    <!-- Html page with checkboxes -->
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <!-- jQuery -->
        <script src="https://code.jquery.com/jquery-3.6.0.js" integrity="sha256-H+K7U5CnXl1h5ywQfKtSj8PCmoN9aaq30gDh27Xc0jk=" crossorigin="anonymous"></script>
        <title>Checkboxes in table </title>
    </head>
    <body>
    
        <table>
            <tr>
                <th> <input type="checkbox" id="selectAll" /> Select All </th>
                <th>First Name</th>
                <th>Last Name</th>
                <th>Email</th>
                <th>Mobile No.</th>
            </tr>
            <tr>
                <td> <input type="checkbox" class="checkbox-item" id="1"/> Checkbox 1 </td>
                <td>Mark</td>
                <td>Otto</td>
                <td>mark@otto.red</td>
                <td>+1-202-555-0154</td>
            </tr>
            <tr>
                <td><input type="checkbox" class="checkbox-item" id="2"/> checkbox 2 </td>
                <td>Jacob</td>
                <td>Thornton</td>
                <td>jacob@thornton.ml</td>
                <td>+44 1632 960733 </td>
            </tr>
        </table>
    </body>
    </html>
    

    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

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Buy Me A Coffee

Don't forget to share this article! Help us spread the word by clicking the share button below.

We appreciate your support and are committed to providing you valuable and informative content.

We are thankful for your never ending support.