猿问

Codeigniter:从下拉列表中选择一个值时更改复选框的值

我有 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,..).


炎炎设计
浏览 94回答 2
2回答

猛跑小猪

查看发票表格页面:-<div class="row space">&nbsp;<label class="control-label">Customer Name<span class="manda">*</span></label>&nbsp;<select class="form-control" name="customerId" id="customerId">&nbsp; &nbsp;<option value="0">Choose Customer Name</option>&nbsp; &nbsp; &nbsp;<?php&nbsp;&nbsp; &nbsp; &nbsp; if ($customer) {&nbsp; &nbsp; &nbsp; &nbsp;foreach ($customer as $row) {&nbsp; &nbsp; &nbsp; &nbsp; echo "<option value='".$row->customerId."'>".$row->customer_name."</option>";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}&nbsp; &nbsp; &nbsp; &nbsp;}&nbsp; &nbsp; &nbsp; ?>&nbsp; &nbsp; &nbsp;</select></div>&nbsp;<div class="row space">&nbsp;<div class="col-sm-6">&nbsp; <div id='billData'></div>&nbsp;</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() {&nbsp; &nbsp; $("#customerId").on("change",function(){&nbsp; &nbsp; var customerId = $(this).val();&nbsp;&nbsp; &nbsp; $.ajax({&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;url : "<?php echo base_url('controler_Name/get_data_in_bill_checkbox') ?>",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;type: "post",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;data: {"customerId":customerId},&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;success : function(data){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //alert(data);&nbsp; &nbsp; $("#billData").html(data);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}&nbsp; &nbsp; });});});</script>控制器代码:-public function get_data_in_bill_checkbox(){&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; $customerId = $this->input->post("customerId");&nbsp; &nbsp; $BillTableDta = $this->db->get_where('bill_address',array('customerId'=>$customerId))->row_array();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$billData = "<label>Bill To</label>";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; foreach($BillTableDta as $bill)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $billData.='<input type="checkbox" name="billcheckbox" value="'.$bill.'">';&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;echo $billData;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}注意:-有关更多参考,请参阅此https://api.jquery.com/change/

幕布斯6054654

您可以使用以下命令让我知道使用三角形是否有效。:-)<div class="row space">&nbsp; &nbsp; <form action="" method="POST">&nbsp; &nbsp; &nbsp; &nbsp; <label class="control-label">Customer <span class="manda">*</span></label>&nbsp; &nbsp; &nbsp; &nbsp; <select class="form-control" name="customerId" onchange="this.form.submit()" id="customerId">&nbsp; &nbsp; &nbsp; &nbsp; <option value="0">Choose....</option>&nbsp; &nbsp; &nbsp; &nbsp; <?php&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ($customer) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; foreach ($customer as $row) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo "<option value='".$row->customerId.'/'.$row->customer_name."'>".$row->customer_name."</option>";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; ?>&nbsp; &nbsp; &nbsp; &nbsp; </select>&nbsp; &nbsp; <?php&nbsp; &nbsp; &nbsp; &nbsp; if(isset($_POST['customerID'])){&nbsp; &nbsp; &nbsp; &nbsp; $true=checked;&nbsp; &nbsp; &nbsp; &nbsp; $data=explode("/",$_POST['customerID']);&nbsp; &nbsp; &nbsp; &nbsp; $id=$data[0];&nbsp; &nbsp; &nbsp; &nbsp; $name=$data[1];&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; else {&nbsp; &nbsp; &nbsp; &nbsp; $true="";&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; ?></div>&nbsp;<div class="row space">&nbsp; &nbsp; <div class="col-sm-6">&nbsp; &nbsp; &nbsp; &nbsp; <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.-->&nbsp; &nbsp; &nbsp; &nbsp; <label><?php if(isset($name) { echo $name; } ?></label>&nbsp; &nbsp; </div></div></form>
随时随地看视频慕课网APP
我要回答