Jquery’s autocomplete documentation seems to be a bit lacking, at least for beginners. I’ve scoured the net for good tutorials, but haven’t found any.
Heres what I have so far:
HTML:
<div id="addfilter">
<div id="textwrap">
<form method="POST" class="homeForm" id="homeForm" action="<?php echo base_url() ?>main/add_filter">
<input type="text" class="text" id="homeText" name="homeText" placeholder="Add Category"></input>
<input type="image" class="imginput" src="<?php echo base_url() ?>img/board/icons/add.jpg"id="homeSubmit" value="X"></input>
</form>
</div>
</div>
JS:
$().ready(function() {
$("text").autocomplete("search.php", {
width: 260,
matchContains: true,
selectFirst: false
});
});
search controller
public function search()
{
$this->thread_model->autocomplete();
}
autocomplete model
public function autocomplete()
{
$query = $this->db->query('SELECT tag
, COUNT(*) as num_items
FROM filter_thread ft
INNER JOIN filter f
ON ft.filter_id = f.filter_id
GROUP BY tag');
$tagcloud = $query->result_array();
foreach ($tagcloud as $tags)
{
echo $tags;
}
}
Firebug doesn’t show anything happening when I input text into ‘formText.’ I’m not even sure if the output of the model is in the correct format. Any help would be appreciated!
Have you tested your controller and model?
First of all I’d correct your jquery:
I’d recomment to supply URL the other way like attribute in form tag:
And before autocomplete in jQuery get that URL:
Autocomplete then sends constraint by in
termparameter. You shoud adjust your query to something like that:I’m not really familiar with CodeIgniter, so you maybe need to correct something.
And the last (maybe) thing is to see how autocomplete will react with returns.