| Subcribe via RSS

Viagra online
XANAXadderall onlineLevitraPuppies for sale

Simple Autocomplete with Scriptaculous

There may be times when you prefer to use a local autocomplete field rather than dropdown (or remote AJAX call). The simplest way is by using Scriptaculous Autocompleter.Local. The basic syntax is as follows:

 
new Autocompleter.Local(field_id,target_div_id,array_of_strings,options);

The first paremeter is the text field id and second is the div id of the autocomplete menu. The third parameter is the data array you are searching. Finally, the fourth are the various options which are as follows:

  • choices - how many results to return (default: 10)
  • partialSearch -If false, will match entered text only beginning of strings. If true, will match text at the beginning of any word in the strings. To search anywhere in the string, also set the option fullSearch to true (default: true)
  • fullSearch - Search anywhere in array.
  • partialChars - Number of characters to enter before searching begins (default: 2)
  • ignoreCase - self-explanatory (default: true)

The following is an example of it's usage:

HTML:

<label for="my_contact_list">List of contacts:</label>
<input id="my_contact_list" size="32" type="text" />
 
<!--div to display results-->
<div class="autocomplete" id="customer_list" style="display:none"></div>
 

Javascript:

 
var contacts = [ 'Atwood, Frank',
'Brower, Karen',
'Drake, Francis',
'Guthry, William',
'Jackson, Mary',
'Lively, Lori',
'Whitley, Marta',
'Zemlicka, Chase'];
new Autocompleter.Local('my_contact_list', 'contact_list', contacts, { });
 

CSS:

div.autocomplete {
  margin:0px;
  padding:0px;
  width:250px;
  background:#fff;
  border:1px solid #888;
  position:absolute;
}
 
div.autocomplete ul {
  margin:0px;
  padding:0px;
  list-style-type:none;
}
 
div.autocomplete ul li.selected {
  background-color:#ffb;
}
 
div.autocomplete ul li {
  margin:0;
  padding:2px;
  height:32px;
  display:block;
  list-style-type:none;
  cursor:pointer;
}
Tags: , , ,

AutoComplete Like “Facebook To:”

Extended Scriptaculous Autocomplete.Local to simulate Facebook's autocomplete address field:

Tags: , , ,