我有三个表,比如:-
invoice_details、customer_details和bill_address。
发票表单有一个dropdown
和一个checkbox
。CCD_ 3列在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>
我怎么能这么做?请帮帮我…
CCD_ 8在所有的CCD_。
表格详细信息:-
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/
您可以使用以下命令,让我知道使用三角形是否有效。:-(
<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>