
How to select all checkbox in Codeigniter
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>[email protected]</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>[email protected]</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.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
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.
Random Code Snippet Queries: CodeIgniter
- Get last executed query in codeigniter
- Unable to set session in codeigniter
- Call to undefined function CodeIgniter\locale_set_default()
- Convert dd/mm/yyyy to yyyy-mm-dd in codeigniter
- Codeigniter 4 call model function from controller
- Get the version codeIgniter
- How to create custom helper in codeigniter 4
- How to move from one view to another in Codeigniter
- How to load a view in CodeIgniter?
- Update an existing table record with +1 in CodeIgniter
- No input file specified Codeigniter
- Default htaccess file code Codeigniter
- How to get field names of table in Codeigniter
- How to call helper function in Codeigniter view