Welcome Guest, Not a member yet? Register   Sign In
Creating an auto-suggest field with jQuery
#3

[eluser]Mike DeFelice[/eluser]
I think I can point you in the right direction, hopefully :-)

This would be inside of a .js file, it's set for 3 or more characters to return a result
Code:
function lookup(inputString) {
    if(inputString.length < 3) {
        // Hide the suggestion box.
        $('#suggestions').hide();
    } else if(inputString.length >= 3) {
        $.post("http://www.example.com/search/searching/", {
            queryString: ""+inputString+""
        }, function(data){
            if(data.length >0) {
                $('#suggestions').show();
                $('#autoSuggestionsList').html(data);
            }
        });
    }
} // lookup

This would call your controller (obviously use your models, views better then the example below), in this example you would have a search controller with a searching function.
Code:
public function searching() {
        //Set validation rules for the form input
        $this->form_validation->set_rules('queryString', 'queryString', 'required|trim|min_length[3]|xss_clean');

        // Validate all of the input, if it passes then show results
        if($this->form_validation->run() !== FALSE) {
YOUR QUERY
            $query = $this->db->get();

            if ($query->num_rows() > 0) {
                // While there are results loop through them
                echo '<ul>';
                foreach ($query->result() as $keyword) {
                    // Format the results, im using <li> for the list, you can change it.    

                    echo '<li>Your keyword link or what not</li>';
                }
                echo '</ul>';
            }
        }
    }

Now in your view just add
Code:
<div id="search">
                        &lt;form action="http://www.example.com/search/" method="post"&gt;
                            &lt;input type="text" name="search"&gt;  
                            &lt;input type="submit" value=""/&gt;
                        &lt;/form&gt;
                        <div class="suggestionsBox" id="suggestions" style="display: none;">  
                            <div class="suggestionList" id="autoSuggestionsList">
  
                            </div>
                        </div>
                      </div>

Now hopefully when you type in your search field some results will appear in the suggestionList.


Messages In This Thread
Creating an auto-suggest field with jQuery - by El Forum - 01-17-2011, 04:21 AM
Creating an auto-suggest field with jQuery - by El Forum - 01-18-2011, 03:33 PM
Creating an auto-suggest field with jQuery - by El Forum - 01-18-2011, 04:37 PM
Creating an auto-suggest field with jQuery - by El Forum - 01-18-2011, 05:28 PM
Creating an auto-suggest field with jQuery - by El Forum - 01-18-2011, 05:36 PM
Creating an auto-suggest field with jQuery - by El Forum - 01-19-2011, 03:09 AM
Creating an auto-suggest field with jQuery - by El Forum - 01-19-2011, 03:58 AM
Creating an auto-suggest field with jQuery - by El Forum - 01-19-2011, 04:11 AM
Creating an auto-suggest field with jQuery - by El Forum - 01-19-2011, 01:43 PM
Creating an auto-suggest field with jQuery - by El Forum - 01-20-2011, 12:06 PM
Creating an auto-suggest field with jQuery - by El Forum - 01-20-2011, 01:40 PM
Creating an auto-suggest field with jQuery - by El Forum - 01-20-2011, 01:44 PM
Creating an auto-suggest field with jQuery - by El Forum - 01-20-2011, 01:51 PM
Creating an auto-suggest field with jQuery - by El Forum - 01-20-2011, 02:34 PM
Creating an auto-suggest field with jQuery - by El Forum - 01-20-2011, 03:16 PM
Creating an auto-suggest field with jQuery - by El Forum - 01-20-2011, 03:47 PM
Creating an auto-suggest field with jQuery - by El Forum - 01-20-2011, 04:12 PM
Creating an auto-suggest field with jQuery - by El Forum - 01-20-2011, 04:35 PM
Creating an auto-suggest field with jQuery - by El Forum - 01-20-2011, 04:47 PM
Creating an auto-suggest field with jQuery - by El Forum - 01-20-2011, 05:01 PM
Creating an auto-suggest field with jQuery - by El Forum - 01-20-2011, 05:06 PM
Creating an auto-suggest field with jQuery - by El Forum - 01-20-2011, 05:17 PM
Creating an auto-suggest field with jQuery - by El Forum - 01-20-2011, 05:45 PM
Creating an auto-suggest field with jQuery - by El Forum - 01-21-2011, 03:07 AM
Creating an auto-suggest field with jQuery - by El Forum - 01-21-2011, 08:59 AM
Creating an auto-suggest field with jQuery - by El Forum - 02-01-2011, 10:54 AM
Creating an auto-suggest field with jQuery - by El Forum - 02-01-2011, 02:44 PM
Creating an auto-suggest field with jQuery - by El Forum - 02-01-2011, 02:47 PM
Creating an auto-suggest field with jQuery - by El Forum - 02-01-2011, 02:55 PM
Creating an auto-suggest field with jQuery - by El Forum - 02-04-2011, 01:49 AM
Creating an auto-suggest field with jQuery - by El Forum - 02-04-2011, 08:35 AM
Creating an auto-suggest field with jQuery - by El Forum - 02-04-2011, 09:34 PM
Creating an auto-suggest field with jQuery - by El Forum - 02-05-2011, 10:23 AM
Creating an auto-suggest field with jQuery - by El Forum - 02-05-2011, 06:06 PM
Creating an auto-suggest field with jQuery - by El Forum - 02-05-2011, 09:26 PM
Creating an auto-suggest field with jQuery - by El Forum - 02-10-2011, 03:59 AM



Theme © iAndrew 2016 - Forum software by © MyBB