When the left checkbox is checked then all the chekbox that are right on the right side must be cheked

  html, javascript, jquery, laravel, laravel-blade

I have tried this code but it only worked once after that i have to refresh the page and then again it will work only once.

 `enter code here`<tr class="all">
                        <!--Guarito=Healed  -->
                        <th style="width:30vh" class="table-info">Guarito</th>


                    @for($i=0;$i<4;$i++)
                            <td>

                        <input  type="checkbox" name="Guarito-{{$i}}" id="Guarito-{{$i}}" class="selectall"

                            @if(!empty($FollowupTreatment[$i] ->guarito) && $FollowupTreatment[$i] ->guarito == 1)
                            checked
                            @endif
                        >
                        </td>


                        </tr>

Here is the code between script tag

$('.selectall').click(function() {

                    if ($(this).is(':checked')) {
                        $('.all input').attr('checked', true);
                    } else {
                        $('.all input').attr('checked', false);
                    }
                });

Source: Laravel

Leave a Reply