Auto suggestion field wont work
Hi, I'm beginner in JQuery please help me, I have search form where users can type some categories about client information, and there's auto suggestions showing under the field coming from MySQL database, I wanted to be more user-friendly, that's why I used field with auto suggestion, after searching over the web, I found one nice tutorial, but the problem is it does not work on mine. I use twitter bootstrap and codeigniter, can you check me out where is my problem? thanks,
view file
- <div class="control-group">
- <label class="control-label">Category Name</label>
-
- <div class="controls">
- <?php
- $params = array(
- 'id' => 'category',
- 'name' => 'category-name',
- 'placeholder' => 'Type in the name of the category',
- 'class' => 'input-xxlarge',
- 'autocomplete' => 'off'
- );
- echo form_input($params);
- ?>
- </div>
- <div id="category-suggestions">
- <div class="suggestions" id="category-autoSuggestionsList">
- </div>
- </div>
- <span class="help-block autocomplete">Start typing the category name. There will be suggestions under a pop-up list. The suggestions list will appear as you write the category name. If your category is found between the suggestions, you can directly click it.</span>
-
- </div>
javascript
- <script src="<?php echo base_url(); ?>assets1/js/jquery-1.7.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var item1 = '#category-suggestions';
var item2 = '#category';
var item3 = '#category-autoSuggestionsList';
$(item1).hide();
function lookup(fieldSuggestions, fieldSuggestionsList, inputString) {
if(inputString.length == 0) {
$(fieldSuggestions).hide();
} else {
$.post("http://www.domain.com/home_members/search_customer/",
{queryString: ""+inputString+""},
function(data){
if(data.length >0) {
$(fieldSuggestions).show();
$(fieldSuggestionsList).html(data);
}
});
}
}
function fill(fieldId, fieldSuggestions, thisValue) {
$(fieldId).val(thisValue);
setTimeout("$('" + fieldSuggestions + "').hide();", 200);
}
$(item2).keyup(function() {
lookup(item1, item3, $(item2).val());
});
$(item3 + " li").live('click', function() {
fill(item2, item1, $(this).attr('title'));
});
});
</script>
search_customer controller
-
function search_customer() {
$this->load->model('customers', 'category');
$query= $this->customers->entries();
foreach($query->result() as $row):
echo "<li title='" . $row->category_name . "'>" . $row->category_name . "</li>";
endforeach;
}
entries Model
tblname: customers
-
- public function entries() {
$this->db->select('category_name');
$this->db->like('category_name', $this->input->post('queryString'), 'both');
return $this->db->get('customers', 10);
}