- <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
- <script>
- $(document).ready(function() {
- $('#selectall').click(function(event) { //on click
- if(this.checked) { // check select status
- $('.checkbox').each(function() { //loop through each checkbox
- this.checked = true; //select all checkboxes with class "checkbox1"
- });
- }else{
- $('.checkbox').each(function() { //loop through each checkbox
- this.checked = false; //deselect all checkboxes with class "checkbox1"
- });
- }
- var chkArray = [];
- $("input[name='check[]']:checked").map(function() {
- chkArray.push(this.value);
- }).get();
- var selected;
- selected = chkArray.join(',') + ",";
- if(selected.length > 1){
- alert(selected);
- } else {
- alert('You have deselected all values');
- }
- });
- });
- </script>
HTML
- <table style="font-size:10px;">
- <tr>
- <th><input type="checkbox" id="selectall" /></th>
- <th>ID</th>
- <th>Profile Name</th>
- <th>Username</th>
- <th>Lastest IPAddress</th>
- </tr>
- @foreach($result as $r)
- <tr>
- <td><input type="checkbox" class="checkbox" name="check[]" value="{{ $r->id }}"></td>
- <td>{{ $r->id }}</td>
- <td>{{ $r->name }}</td>
- <td>{{ $r->username }}</td>
- <td>{{ $r->lastest_ipaddress }}</td>
- </tr>
- @endforeach
- </table>