este es el controller
public function getarticulos() {
$q = trim($this->input->get('term'));
$where = array('like codigo' => $q);
$productoresult = $this->articulo_model->All($where);
$result = array();
foreach ($productoresult as $i =>$articulo) {
$result[$i]['id'] = $articulo->id;
$result[$i]['codigo'] = $articulo->codigo;
$result[$i]['descripcion'] = $articulo->descripcion;
$result[$i]['precioactual'] = $articulo->precioactual;
}
echo json_encode($result);
}
vista
<script type="text/javascript">
$("#txtcodigo").autocomplete({
source: "<?php echo base_url() ?>index.php/articulo/getarticulos",
minLength: 3,
select: function( event, ui ) {
if(ui.item.id){
$("#txtcodigo").val(ui.item.codigo);
return false;
}
},
search: function (event, ui ){
$("#txtcodigo").val(0);
}
});
</script>
<div class="form-group">
<div class="col-xs-6">
<div class='input-group' id="the-basics">
<span class="input-group-addon"><span class="glyphicon glyphicon-tag"></span></span>
<input id="txtcodigo" name="codigo" type="text" placeholder="Codigo" class="form-control" required="">
<input id="txtid" name="id" type="hidden" placeholder="id" class="form-control" required="">
</div>
</div>
</div>
DESDE YA GRACIAS