8 thoughts on “Ajax autocompletion for the impatient

  1. I can’t pass the id in the hidden field. I put the function

    function getSelectedId(text, li) {

    before my form, because if I put it after I take error because element getSelectedId is not yet set for the function Ajax.Autocompleter to call it.

    But even I tried all the ways that I can think, I did not managed to get this work, to pass the id in a hidden input field.

    My page code is :

    function getSelectedId(text, li) {

    ÁíáæÞôçóç ÌÝëïõò :


    new Ajax.Autocompleter(“search”,”hint”,”server.php”,{afterUpdateElement : getSelectedId});

    And my server.php is :

    $test_echo = $_POST['search'];

    $test_echo = str_replace(“A”, “Á”, $test_echo);
    $test_echo = str_replace(“B”, “”, $test_echo);
    $test_echo = str_replace(“G”, “Ô, $test_echo);
    $test_echo = str_replace(“D”, “Ä”, $test_echo);
    $test_echo = str_replace(“E”, “Å”, $test_echo);
    $test_echo = str_replace(“Z”, “Æ”, $test_echo);
    $test_echo = str_replace(“H”, “Ç”, $test_echo);
    $test_echo = str_replace(“U”, “È”, $test_echo);
    $test_echo = str_replace(“I”, “É”, $test_echo);
    $test_echo = str_replace(“K”, “Ê”, $test_echo);
    $test_echo = str_replace(“L”, “Ë”, $test_echo);
    $test_echo = str_replace(“M”, “Ì”, $test_echo);
    $test_echo = str_replace(“N”, “Í”, $test_echo);
    $test_echo = str_replace(“J”, “Δ, $test_echo);
    $test_echo = str_replace(“O”, “Ï”, $test_echo);
    $test_echo = str_replace(“P”, “Д, $test_echo);
    $test_echo = str_replace(“R”, “Ñ”, $test_echo);
    $test_echo = str_replace(“S”, “Ó”, $test_echo);
    $test_echo = str_replace(“T”, “Ô”, $test_echo);
    $test_echo = str_replace(“Y”, “Õ”, $test_echo);
    $test_echo = str_replace(“F”, “Ö”, $test_echo);
    $test_echo = str_replace(“X”, “×”, $test_echo);
    $test_echo = str_replace(“C”, “Ø”, $test_echo);
    $test_echo = str_replace(“V”, “Ù”, $test_echo);

    $keywords = $test_echo;
    $search_name = ” where customers_lastname like ‘%” . $keywords . “%’ or customers_fax = ‘” . $keywords . “‘”;
    $search_name = $db->bindVars($search_name, ‘:keywords:’, $keywords, ‘regexp’);
    $sql = “SELECT customers_fax, customers_lastname, customers_firstname
    FROM customers
    ” . $search_name . ”

    $rs = mysql_query($sql);


    <li id =”" title=”" class=”lista_li”>

    echo $data['customers_lastname'].’ ‘.$data['customers_firstname'].’   AM : ‘.$data['customers_fax'].”;


    I had to search with LATIN characters, because there was a problem with GREEK characters. So when LATIN characters are posted, they are replaced with GREEK characters. And wehen someone wants to search records with LATIN characters in database, he can use lowercase because I replace only upercase characters.

  2. Hi Tim. I write from Argentina. I´m trying your script, and works fine, but I find a little trouble: in your demo, I can select a suggestions with arrows key + enter, but in my installation I can´t, only allow to select using mouse. Can you giveme a tip to find a solution? I´m using Linux CentOS 5.2 + Apache 2.2 + PHP 5.2 + Last Scriptaculous Library. Too Xampp 1.7 for Windows. Thanks very much in advance.

  3. does this script re-query the database with each keystroke or simply complete off of the result data from one query? If it continually queries, you could run into serious memory issues.

    Look forward to your reply

  4. Cheap levitra the prescription erectile dysfunction (ED) tablet clinically proven to both work fast (in as little as 30 minutes for some men) and work up to 36 hours For cialis kamagra fast delivery Europe! No prescription required-buy levitra tabs .. Fast to get erectile dysfunction pills online. Find out more about viagra at the official vigara online usa site…
    Go to order dosing cials now!

  5. Tadalafil is taken orally and helps men suffering from erectile dysfunction achieve and maintain an erection For viagra generic soft tabs very fast delivery for you! Save your money -buy cialis pill … Easy to get cialis pills online. Find out more about sexual activity at the great calis pfizer site.
    canadian generic levirta ukonline…

  6. Cheap cialis is taken orally and helps men suffering from erectile dysfunction achieve and maintain an erection For cialis order usa fast delivery Usa. No prescription required -buy priaprism pills now.. Fast to get cialis pills online… Find out more about erectile dysfunction at the great viagara herbal site
    Buy now canada tadafil …

  7. Heya,

    So I am working on something similar.
    A piece of advice, for the PHP to this:

    instead of writing all those str_replace, either do a for() loop for all latin Char(), or just make an array.


  8. I was just trying your autocompletion demo and it works just fine, but how can I do that when somebody select an option the script fill a hidden input with another info of the same SQL query.

    To be more clare, I need to search by name a database of customers but when I found the person by his name I need to load his identification in a hidden input.

    Thanks for all

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>