jeudi 2 novembre 2017

checkbox checking all siblings of nested checkbox inside a td

please help me how to: check all the siblings if the checkbox parent is check, and also if some child/children of a checkbox was checked, then the parent also must be checked. How can i do this?

i have this in my laravel code:

<table class="table table-hover" id="tableOrders">                                    
    <thead class="thead-inverse">                        
        <tr>
          <th width="4%"><input type="checkbox" id="selectAll" /></th>
          <th width="7%">USER ID</th>
          <th width="12%">AMOUNT</th>
          <th width="15%">SHIP DATE</th>
          <th width="15%">RECEIVER</th>
          <th width="20%">ADDRESS</th>
          <th width="14%">MOBILE #</th>
        </tr>
    </thead>                        
    <tbody>
         <?php $i=0 ?>                             
         @foreach($shippings as $data)                             
        <tr>

            <td><input type="checkbox" class="parent" name="shippings[][]" value="" />&nbsp;</td>                                
            <td><a href="#" data-value="" class="linkedit">  </a></td>
            <td><a href="#" data-value="" class="linkedit">  </a></td>
            <td><a href="#" data-value="" class="linkedit">  </a></td>
            <td><a href="#" data-value="" class="linkedit">  </a></td>
            <td><a href="#" data-value="" class="linkedit">  </a></td>   
            <td><a href="#" data-value="" class="linkedit">  </a></td>                                
        </tr>
        <tr>
            <td></td>
            <td></td>
            <td><p style="font-weight:bold;">Product Name</p></td>
            <td><p style="font-weight:bold;">Price</p></td>
            <td><p style="font-weight:bold;">Ordered Qty</p></td>
            <td><p style="color:red;font-weight: bold;">Available Qty</p></td>
        </tr>                              
          @foreach($data->products as $product)

                <tr>
                  <td></td>
                  <td><input type="checkbox" class="child" name="shippings[][products][]" value="" />&nbsp;</td>                
                  <td></td>
                  <td></td>                              
                  <td></td>
                  <td><p style="color:red;"> </p></td>                                      
                </tr>                              
          @endforeach                        
          <?php $i++; ?>                            
        @endforeach
    </tbody>
</table>

I have my jsfiddle link:

http://ift.tt/2lIj7mb

I am very confused because i did it in my laravel loop, but the structure of it is in the jsfiddle.




Aucun commentaire:

Enregistrer un commentaire