Welcome Guest, Not a member yet? Register   Sign In
Onchange function using ajax in View
#1

Hi! I've an autocomplete input form with id 'poscustomer' . I want to display previous total balance whenever I select a customer.
I tried this but no results. would you please tell me which part of this code needs to be edited . Thanks

controller
function dispdata()
    {

    $poscustomer = $this->input->post('poscustomer',TRUE);
        $data['totalbalance'] =$this->pos_model->getBalance($poscustomer)->result();
    echo json_encode($data);
       
}


Model
public function getBalance($poscustomer)
{
      $this->db->select('SUM(grand_total - paid) as totalbalance', false);
      $this->db->where('sales', array('customer' => $poscustomer));
      return $result->totalbalance;
}

Javascript code in the view folder
$(document).ready(function(){
  $('#poscustomer').change(function(){
  var poscustomer=$(this).val();
$.ajax({
url    : "<?=admin_url('pos/dispdata');?>",
type: "POST",
data : {poscustomer: poscustomer},
cache: false,
dataType: 'json',
        success: function(data){
//alert(data);

    $('#totalbalance').val(totalbalance);
}
});
});
});
Reply


Messages In This Thread
Onchange function using ajax in View - by jordi_1h - 04-20-2020, 09:48 PM



Theme © iAndrew 2016 - Forum software by © MyBB