php - Codeigniter:从下拉列表中选择一个值更改复选框的值
问题描述
我有 3 张桌子说:-
invoice_details、customer_details 和 bill_address。
发票表格有一个dropdown
和一个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,..).
解决方案
发票表格的查看页面:-
<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/
推荐阅读
- c# - [SerializationException: Typen System.Drawing.Imaging.ImageFormat 尝试保存位图时
- python - 使用 conda env 在 Mac 上的 PyCharm 中运行时,“ffmpy”找不到“ffmpeg”
- python - Python Selenium 修改和运行脚本
- python - 不“等待”的协程与函数有什么不同吗?
- ruby - 有条件的计数数组
- c++ - boost::lockfree:queue 中的内存排序
- laravel-5 - 更改域后的laravel不起作用链接
- python - Python - 读取格式不正确的 xml 文件
- java - 我无法在 Spring Boot 中使用 google pubsub 模拟器发送消息
- excel - 运行时错误“1004”:应用程序定义或对象定义错误