Autofills add fields on dropdown change
- Single Page
Posted 23 April 2012 - 03:59 AM
Is there a way to add a functionality that will autofill some fields on a form on dropdown change.
I have a customer table and a service request table, I have set a relation between this 2 table. But I want is to get the data from the customer table so if I select on a dropdown list of customer. on change it will autofill the address and other fields.
BTW grocery CRUD is the best CRUD i have seen so far.
Posted 23 April 2012 - 06:04 AM
so for example you can have:
$('input[name=customer_name]').change(function(){
$.ajax({
url: 'whatever',
dataType:'json',
success: function(result){
$('input[name=address]').val(result.address);
$('input[name=postcode]').val(result.postcode);
}
});
});
Ok I just write this script on my mind but you get the point
Posted 23 April 2012 - 09:11 AM
Can I just echo this on my controller before going to the form.
...
$output=$crud->render();
echo "$('input[name=customer_name]').change(function(){
$.ajax({
url: 'example/getAddress/'.$('input[name=customer_name]'),
dataType:'json',
success: function(result){
$('input[name=address]').val(result.address);
$('input[name=postcode]').val(result.postcode);
}
});
});";
$this->load->view('example.php',$output);
}
and how can I past the input to the another url to get the the values.
on another page:
function getAddress($where){
$query=$this->db->query('Select address,zipcode from Customer where
customerid =' .$where) ;
}
how to format the result to json so I can return it to other fields.