How to create an autocomplete textbox in register page - Drupal 6 Consider I am doing a registration form with the following fields.

1. Name

2. Email

3. City


Here the city should be auto complete.

I created the city field with the help of content profile module in order to add more fields in future.

Now how can i make the "City" text box auto complete.

How can i store the records in the table ?

Thanks in advance...
There's a full example for Drupal 6 here: [Textfield that uses autocomplete][1]. The code will probably be useful to people on this site as well so I'll post i here:

The following is based on a module with the name: 'cities'

In your form function:

$form['city'] = array(
  '#type' =&gt; 'textfield',
  '#title' =&gt; 'City',
  '#maxlength' =&gt; 128,
  '#autocomplete_path' =&gt; 'cities/autocomplete',
);


In your module file:

function cities_menu(){
  // path with autocomplete function for cities
  $items['cities/autocomplete'] = array(
    'title' =&gt; 'Autocomplete for cities',
    'page callback' =&gt; '_cities_autocomplete',
    'access arguments' =&gt; array('use autocomplete'),  //or whatever permission makes sense
    'type' =&gt; MENU_CALLBACK
  );
  return $items;
}


Also in your module file:

function _cities_autocomplete($string) {
  $matches = array();
  //search table `cities` for cities that begin with the letters the user enters in the form
  $result = db_query_range("SELECT city FROM {cities} WHERE LOWER(city) LIKE LOWER('%s%')", $string, 0, 10);
  // add matches to $matches
  while ($data = db_fetch_object($result)) {
    $matches[$data-&gt;city] = check_plain($data-&gt;city);
  }
 print drupal_to_js($matches);

}