Autocomplete results in a HTML listbox I am using autocomplete from drupal so that users can be guided into finding what they are looking for. For an even better user experience it would be great if autocomplete is returning the results in a listbox. I just started to learn drupal programming (and loving it :) ) but I can't find anything on this particular question.

At this moment when I start typing in a textarea, drupal will show a selection of approx. matches in a pulldown list. How do I get those matches in a html listbox?

I am using the code below for autocompletion

/**
* autocomplete helper
* $string = string for search
*/
function _complete_autocomplete($string) {
  $matches = array();
  $result = db_select('notebooks', 'c')
    -&gt;fields('c', array('product'))
    -&gt;condition('product', '%' . db_like($string) . '%', 'LIKE')
-&gt;range(0, 10)
    -&gt;execute();

  // save the query to matches
  foreach ($result as $row) {
    $matches[$row-&gt;product] = check_plain($row-&gt;product);
  }
  // Return the result to the form in json
  drupal_json_output($matches);
}
Okay I got a bit working. But it only fills the select options after the textfield is losing focus. How can I make it so that while typing in the textfield, the select options is filled with data. Kinda similar as to autocomplete?

And another question, if i press enter I get an HTTP error . An Ajax HTTP request terminated abnormally. path: /?=system/ajax
status : text
responsetext:
ready/state:4

Any ideas why this is happing?

&lt;?php

function dropdown_menu(){

$items['test/drop'] = array(
'title' =&gt; 'Fill select options from db',
'page callback' =&gt; 'drupal_get_form',
'page arguments' =&gt; array('select_dropdown'),
'access callback' =&gt; TRUE,
'weight' =&gt; 4,
'type' =&gt; MENU_NORMAL_ITEM,
);

return $items;
}

function dropdown_submit($form, &amp;$form_state) {
//dpm($form);
drupal_set_message('Submit handler was called.');
}

function select_dropdown($form, &amp;$form_state) {

$form['searchfield'] = array(
        '#title' =&gt; t('Search database and fill select options'),
        '#type' =&gt; 'textfield',
        '#required' =&gt; TRUE,
        '#maxlength' =&gt; 115,
        '#size' =&gt; 55,
        '#weight' =&gt; 0,
'#default_value' =&gt; 'look for it',
'#ajax' =&gt; array(
  'event' =&gt; 'change',
  'callback' =&gt; 'search_db',
  'wrapper' =&gt; 'dropdown-second-replace',
),
    );

  // Get the list of options to populate the first dropdown.
$options_first = _drop_get_first_dropdown_options();
$selected = isset($form_state['values']['searchfield']) ? $form_state['values']['searchfield'] : key($options_first);
$form['dropdown_second'] = array(
'#type' =&gt; 'select',
'#title' =&gt; 'Options filled from db',
'#prefix' =&gt; '&lt;div id="dropdown-second-replace"&gt;',
'#suffix' =&gt; '&lt;/div&gt;',
'#size'=&gt;10,
'#options' =&gt; _drop_get_second_dropdown_options($selected),
'#default_value' =&gt; isset($form_state['values']['dropdown_second']) ? $form_state['values']['dropdown_second'] : '',
);


//  $form['submit'] = array(
// '#value' =&gt; 'Submit',
//   '#type' =&gt; 'submit',
// '#submit' =&gt; array('dropdown_submit')
// );

  return $form;
}


function drop_dependent_dropdown_callback($form, $form_state) {
return $form['dropdown_second'];
}

function search_db($form, $form_state) {
return $form['dropdown_second']; 
}


// normally pulling data from the database.
function _drop_get_first_dropdown_options() {
return drupal_map_assoc(array(t('empty')));
}

function _drop_get_second_dropdown_options($key = '') {
$matches = array();
$result = db_select('tabel', 'c')
-&gt;fields('c', array('product', 'xtra'))
-&gt;condition('product', '%' . db_like($key) . '%', 'LIKE')
// -&gt;range(0, 10)
-&gt;execute();

// save the query to matches
foreach ($result as $row) {
$matches[$row-&gt;product] = check_plain($row-&gt;product) . ' xtra:' . ($row-&gt;xtra);
}
return($matches);

}