vendredi 12 juin 2020

how will i able to change dynamically on the select dropdown based on the first selection using Jquery im using Laravel 5.4

Hi i have this two select dropdown the first dropdown will select then the second dropdown will get the data based on the first selection. Now my problem is how will i able to update this based on what select dropdown first chooses. My code works but the problem is everytime i change and choose the select dropdown the data will keep on inserting using the append. I want only on what the select data will get. Here is my code below.

 <div id="drNo" class="col-lg-2">
                                      <label>DR #</label>
                                      <select data-live-search="true" name="drNo" class="drSelect form-control selectpicker">
                                        <option value="0">--Please Select--</option>
                                        @foreach($drNos as $drNo)
                                        <option value=""></option>
                                        @endforeach
                                      </select> 
                                  </div>
                                <div id="drList" class="col-lg-2">
                                    <label>DR Lists Id</label>
                                    <select id="dataList" name="drList" class="chooseDr form-control "> 
                                    </select>
                                </div>





 $(".drSelect").change(function(){
        <?php
             $moduleName = "Delivery Receipt"; 
             $getDrNos = DB::table(
                             'lechon_de_cebu_delivery_receipts')
                             ->select( 
                             'lechon_de_cebu_delivery_receipts.id',
                             'lechon_de_cebu_delivery_receipts.user_id',
                             'lechon_de_cebu_delivery_receipts.dr_id',
                             'lechon_de_cebu_delivery_receipts.dr_no',
                             'lechon_de_cebu_delivery_receipts.sold_to',
                             'lechon_de_cebu_delivery_receipts.delivered_to',
                             'lechon_de_cebu_delivery_receipts.time',
                             'lechon_de_cebu_delivery_receipts.date',
                             'lechon_de_cebu_delivery_receipts.date_to_be_delivered',
                             'lechon_de_cebu_delivery_receipts.contact_person',
                             'lechon_de_cebu_delivery_receipts.mobile_num',
                             'lechon_de_cebu_delivery_receipts.qty',
                             'lechon_de_cebu_delivery_receipts.unit',
                             'lechon_de_cebu_delivery_receipts.description',
                             'lechon_de_cebu_delivery_receipts.price',
                             'lechon_de_cebu_delivery_receipts.total',
                             'lechon_de_cebu_delivery_receipts.special_instruction',
                             'lechon_de_cebu_delivery_receipts.consignee_name',
                             'lechon_de_cebu_delivery_receipts.consignee_contact_num',
                             'lechon_de_cebu_delivery_receipts.prepared_by',
                             'lechon_de_cebu_delivery_receipts.checked_by',
                             'lechon_de_cebu_delivery_receipts.received_by',
                             'lechon_de_cebu_delivery_receipts.duplicate_status',
                             'lechon_de_cebu_delivery_receipts.created_by',
                             'lechon_de_cebu_codes.lechon_de_cebu_code',
                             'lechon_de_cebu_codes.module_id',
                             'lechon_de_cebu_codes.module_code',
                             'lechon_de_cebu_codes.module_name')
                             ->join('lechon_de_cebu_codes', 'lechon_de_cebu_delivery_receipts.id', '=', 'lechon_de_cebu_codes.module_id')
                             ->where('lechon_de_cebu_delivery_receipts.dr_id', NULL)
                             ->where('lechon_de_cebu_codes.module_name', $moduleName)
                             ->get();

          ?>
        const dr = $(this).children("option:selected").val();
        <?php foreach($getDrNos as $getDrNo ): ?>
             if(dr === "<?php echo $getDrNo->lechon_de_cebu_code?>"){
                <?php 
                    $getDrNosInsides = DB::table(
                                    'lechon_de_cebu_delivery_receipts')
                                    ->where('dr_no', $getDrNo->dr_no)
                                    ->get(); ?>


                  <?php foreach($getDrNosInsides as $getDrNosInside):?>
                       $("#dataList").append(  
                          `<option value="<?php echo $getDrNosInside->id?>"><?php echo $getDrNosInside->id?></option>
                          `);


                        });       

                    <?php endforeach; ?>    
                $("#qty").html('<label>Qty</label><input type="text" name="qty" value="<?php echo $getDrNo->qty; ?>" class="form-control" readonly="readonly" />');
                $("#unit").html('<label>Unit</label><input type="text" name="qty" value="<?php echo $getDrNo->unit; ?>" class="form-control" readonly="readonly" />');

                $("#wholeLechon6000").html('<label>Whole Lechon</label><input type="text" name="wholeLechon6000" value="<?php echo $getDrNo->price; ?>" class="form-control" readonly="readonly" />');
                $("#descriptionDrNo").html('<label>Description</label><input type="text" name="descriptionDrNo" value="<?php echo $getDrNo->description; ?>" class="form-control" readonly="readonly" />');
             }

        <?php endforeach; ?>

Can someone help me figured this thing out? Anyhelp is muchly appreciated. TIA



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/37lpd0e
via IFTTT

Aucun commentaire:

Enregistrer un commentaire