亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Codeigniter:從下拉列表中選擇一個值時更改復選框的值

Codeigniter:從下拉列表中選擇一個值時更改復選框的值

PHP
炎炎設計 2023-09-22 14:50:55
我有 3 張桌子說:-發票詳細信息、客戶詳細信息和帳單地址。發票表格有adropdown和 a checkbox。Customer names列在下拉列表中customer table。當我選擇一個customer name復選框值時,必須具有相應的billId.因此,當我標記復選框時,復選框的值必須是billId已選擇的客戶名稱。我希望我的問題很清楚。查看頁面:-<div class="row space"> <label class="control-label">Customer <span class="manda">*</span></label> <select class="form-control" name="customerId" id="customerId">   <option value="0">Choose....</option>     <?php       if ($customer) {       foreach ($customer as $row) {        echo "<option value='".$row->customerId."'>".$row->customer_name."</option>";      }     } ?>     </select></div> <div class="row space"> <div class="col-sm-6">  <input type="checkbox" name="checkbox" value="bill">  <label>Bill To</label> </div></div>我怎么能這樣做呢?請幫我...customerId是普遍存在的3 tables。表格詳細信息:-bill_address(billId, customerId, street, city, state, country).customer_details(customerId, customer_name, phone, email,..).invoice_details(invoiceId, customerId, billId, date, status,..).
查看完整描述

2 回答

?
猛跑小豬

TA貢獻1858條經驗 獲得超8個贊

查看發票表格頁面:-


<div class="row space">

 <label class="control-label">Customer Name<span class="manda">*</span></label>

 <select class="form-control" name="customerId" id="customerId">

   <option value="0">Choose Customer Name</option>

     <?php 

      if ($customer) {


       foreach ($customer as $row) {


        echo "<option value='".$row->customerId."'>".$row->customer_name."</option>";

         }

       }

      ?>


     </select>

</div> 

<div class="row space">

 <div class="col-sm-6">

  <div id='billData'></div>

 </div>

</div>

Jquery Ajax 代碼:-在關閉標簽之前在發票表單視圖頁面中添加此代碼</body>。


<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>


<script>

$(document).ready(function() {

    $("#customerId").on("change",function(){

    var customerId = $(this).val();

 

    $.ajax({

         url : "<?php echo base_url('controler_Name/get_data_in_bill_checkbox') ?>",

         type: "post",

         data: {"customerId":customerId},

         success : function(data){

            //alert(data);

    $("#billData").html(data);

         }

    });

});

});

</script>

控制器代碼:-


public function get_data_in_bill_checkbox(){

    

    $customerId = $this->input->post("customerId");


    $BillTableDta = $this->db->get_where('bill_address',array('customerId'=>$customerId))->row_array();

           

           $billData = "<label>Bill To</label>";

              foreach($BillTableDta as $bill)

              {

                $billData.='<input type="checkbox" name="billcheckbox" value="'.$bill.'">';

              }

               echo $billData;

           }

注意:-有關更多參考,請參閱此https://api.jquery.com/change/


查看完整回答
反對 回復 2023-09-22
?
幕布斯6054654

TA貢獻1876條經驗 獲得超7個贊

您可以使用以下命令讓我知道使用三角形是否有效。:-)


<div class="row space">

    <form action="" method="POST">

        <label class="control-label">Customer <span class="manda">*</span></label>

        <select class="form-control" name="customerId" onchange="this.form.submit()" id="customerId">

        <option value="0">Choose....</option>

        <?php 

            if ($customer) {


            foreach ($customer as $row) {


            echo "<option value='".$row->customerId.'/'.$row->customer_name."'>".$row->customer_name."</option>";

            }


            } 

        ?>

        </select>

    <?php

        if(isset($_POST['customerID'])){

        $true=checked;

        $data=explode("/",$_POST['customerID']);

        $id=$data[0];

        $name=$data[1];

        }

        else {

        $true="";

        }

    ?>

</div> 

<div class="row space">

    <div class="col-sm-6">

        <input type="checkbox" <?php if(isset($true){ echo $true; } ?> name="checkbox" value="<?php if(isset($id){ echo $id; } ?>"> <!-- you can change this $id to $name based on your need.-->

        <label><?php if(isset($name) { echo $name; } ?></label>

    </div>

</div>

</form>


查看完整回答
反對 回復 2023-09-22
  • 2 回答
  • 0 關注
  • 129 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號