Controller
Code: Select all
public function index()
{
$this->load->model('sales/Sales_model');
$this->load->model('product/Product_model');
$user_info['p_info'] = $this->Product_model->fetch_data();
$this->load->view('sales/index', $user_info);
}
public function get_pcatagory()
{
$this->load->model('sales/Sales_model');
$pid = $this->input->post('pro_id');
$cat_info = $this->Sales_model->fetch_data_pid($pid);
if (count($cat_info) > 0) {
$select_box = '';
$select_box .= 'Select Catagory ID';
foreach ($cat_info as $value) {
// $value->id data will go to option of the select menu
}
echo json_encode($select_box);
}
}
Code: Select all
public function fetch_data_pid($pid)
{
$query = $this->db->get_where('product', array('id' => $pid));
return $query->result();
}
Code: Select all
$(document).ready(function(){
$('#pid').on('change',function(){
var pro_id_data = $('#pid').val();
alert(pro_id_data);
$.ajax({
url: 'sales/get_pcatagory',
type: 'POST',
data: {'pro_id' : pro_id_data},
dataType: 'json',
success:
function(result){
$('#cate').html(result);
},
error:
function(){
alert('error')
}
});
});
});
Code: Select all
Product ID
Select Product ID
Mobile version