[eluser]Blinkiz[/eluser]
I just wanted to share a working code that am using.
Don't forget to include the css file for the jquery ui in your header.
View
[removed] is the script tags for loading "data/jquery-1.4.3.min.js" and "data/jquery-ui-1.8.6.custom.min.js".
Much html code is removed to make it easier to read.
Code:
<div class="moduletable">
<form Method="POST" Action="<?php echo site_url(); ?>people/add" Name="addperson">
<table>
<tr>
<td>
Person name<br />
<input id="name" name="name" value="" /><br />
</td>
</tr>
</tbody>
</table>
</form>
</div>
<!-- javascripts -->
[removed][removed]
[removed][removed]
[removed]
$(function() {
$( "#name" ).autocomplete({
source: '<?php echo site_url('search/search_person_name/');?>',
search: function(event, ui)
{
$("#name").autocomplete("option", "source", "<?php echo site_url('search/search_person_name/');?>/"+$("#name").val());
}
});
});
[removed]
Controller
Code:
function search_person_name()
{
echo json_encode($this->searchmodel->search_person_name($this->uri->segment(3)));
}
Model
Code:
function search_person_name($search)
{
$query = $this->db->select('cp.id,cp.name')->from('contactpersons cp')->like('cp.name', $search)->get();
foreach($query->result_array() as $name)
{
$data[] = array('label' => $name['name'], 'value' => $name['name'], 'id' => $name['id']);
}
return $data;
}