Thursday, April 13, 2017

Checkbox - allow to check only one checkbox

I was to trying to update my checkbox value based on checked..But the problem I'm facing is i can't uncheck the old checkbox checked ..So when i click on the new checkbox the old one should be uncheck...I have used laravel platform where table header comes from database and from database the old checkbox value came..

here is my blade view :

<table class="table">
                        <thead>
                          <tr>
                            <th>SL No</th>
                            <th>Name</th>
                         @foreach($roles as $row)         
                            <th></th>
                         @endforeach
                          </tr>
                        </thead>
                         <tbody>
                        <?php $i=1; ?>
                        @foreach($users as $user)
                            @foreach($user->roles as $row)
                            <tr>
                                <td></td>
                                <td></td>

                              @foreach($roles as $role)
                              <td>

                               @if($role->role == $row->role)
                                    <input type="checkbox" class="myCheckbox" checked="" value="1" >
                               @else 
                                    <input type="checkbox" class="myCheckbox" value="0"  >
                               @endif

                               </td>    
                               @endforeach
                            </tr>
                            <?php $i++; ?>
                            @endforeach
                        @endforeach
            </tbody>
                      </table>

Here is the javascript i used for check only one checkbox .

 $('.myCheckbox').click(function() {
    $(this).siblings('input:checkbox').prop('checked', false);
});

anybody could help me to find out the solution please?



via User57

Advertisement