I have 3 tables say:-
invoice_details, customer_details and bill_address.
The invoice form has a dropdown and a checkbox. Customer names are listed in the dropdown from the customer table. And when I select a customer name the checkbox values must have the corresponding billId.
so when I mark the checkbox, the value of checkbox must be the billId of that customer name that has been selected. I hope my question is clear.
view page:-
<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>
How could I do this? please help me…
customerId is common in all 3 tables.
Table details:-
bill_address(billId, customerId, street, city, state, country). customer_details(customerId, customer_name, phone, email,..). invoice_details(invoiceId, customerId, billId, date, status,..).
Advertisement
Answer
view page of Invoice Form:-
<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 Code:- Add this code in Invoice Form view Page before closing </body> Tag.
<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>
Contoller Code:-
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;
}
Note:- For more Reference see this https://api.jquery.com/change/