Ajaxian Featured Tutorial: AutoCompleter 101

Written by on September 24th, 2007 in Ajax News.

Jamie Mcconnell has taken the age old classic Ajax autocompleter, and has created a simple tutorial using jQuery and PHP. Jamie takes time to explain the “why” as much as the “how”:

JAVASCRIPT:

  1.  
  2. <script src=”jquery-1.2.1.pack.js” type=”text/javascript”></script><script type=”text/javascript”>
  3.  
  4. function lookup(inputString) {
  5.     if(inputString.length == 0) {
  6.         // Hide the suggestion box.
  7.         $(‘#suggestions’).hide();
  8.     } else {
  9.         $.post(”rpc.php”, {queryString: “”+inputString+”"}, function(data){
  10.             if(data.length>0) {
  11.                 $(‘#suggestions’).show();
  12.                 $(‘#autoSuggestionsList’).html(data);
  13.             }
  14.         });
  15.     }
  16. } // lookup
  17.  
  18. function fill(thisValue) {
  19.    $(‘#inputString’).val(thisValue);
  20.    $(‘#suggestions’).hide();
  21. }
  22. </script>
  23.  

You can see it in action and download the source.

Source: Ajaxian
Original Article: http://feeds.feedburner.com/~r/ajaxian/~3/160586843/ajaxian-featured-tutorial-autocompleter-101

Leave a Reply

You must be logged in to post a comment.



Site Navigation