How to use the code

Copy the entire autocomplete function and put it somewhere in your code.

Add the event onkeyup='autocomplete(this,fruits)' in the textbox. Note that the 2nd argument should tally with the array name you defined at 1.

Add the property backspace='false' in the textbox. The backspace property is applicable when a user press backspace in the textbox. It gets very irritating without the boolean; i.e. when the user press backspace, the highlighted characters get deleted, but it will automatically be replaced by the same characters due to the autocomplete.

Todo

I've tested the autocomplete control with an array of size 150. The speed was pretty reasonable on my computer (P3 700Mhz). However, I'm sure the autocomplete function's string-matching algorithm can be further improved upon.

Allow for case insensitive string-matching

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

PHP PEAR class can make life much simpler.
Demostrated below is a sample of how PHP PEAR library can be used to implement AutoComplete functionality of a text box.
<?php
require 'HTML/QuickForm.php';
$teams = array('Amit','Satyan','Saswat','Chinmoya','Sonali','Kiran','Ansuman','Hemendra');
$form = new HTML_QuickForm();
$element =& $form -> addElement('autocomplete','teams','Favorite Engg Team:');
$element -> setOptions($teams);
$form->display();
?>
Now, save the file in a virtual directory and access it from browser. The text box would be populated with the values hard-coded above.

I'm still looking for multiple autocomplete in the same input text (like the
Outlook's input texts ("to", "cc", "bcc"). When you complete one mail address..
the autocomplete "restarts" but now.. for the second word...