Try something like this, You may need to change the code slightly to suit you,
In your script part:
$("#individual_name").autocomplete({
source : base_url+"controller_name/suggest_names",
minLength : 1,
select: function( event, ui ) {
alert('id :'+ui.item.value) ;
//document.location.href = base_url+"controller_name/search?keyword="+ui.item.value; do something or redirect
},
success : function(resp){
//alert("auto");
},
error : function(){
alert("Oops, that didn't work. Please try again.");
}
});
In your controller:
function suggest_names(){
print_r ( $this->model_name->suggest_names($_REQUEST['term']) );
}
In your model part:
function suggest_names($term){
$data = array();
$term = strtolower( addslashes( trim( urldecode($term) ) ) );
$temp = $this->db->select('name as label, id as value')->like('name', $term, 'LEFT')->get('table_name')->result_array();
$data = json_encode($temp);
//echo "<pre>";print_r($data);echo "</pre>";die;
return $data;
}
Let me know if you face any problem. Hope it works for you.