Hi All,

I just spent more time finding the right plug-in than getting it to
work. jQuery is becoming an amazing and mature resource for web
developers! I'm writing this post in hopes that the next "me" who
comes along trying to get autocomplete working will find the info.

Be sure to download the plug-in from 
http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/
Big thanks to Jörn for this plug-in!! Since I had problems finding
sample working code, I thought I would share some:


I'm writing a phone order page for our internal webserver...

$('input.sku').autocomplete("autocomplete_sku.php")
        .result(function(event, data, formatted) {
                // alert( $.dump(data) );
                //      Array (
                //              0 => "12-0012"
                //              1 => "Brake Light Switch"
                //              2 => "19.00"
                //      )
                var id=$(this).parent().parent().attr("id");
                $('tr#'+id+' > td > input.item').attr("value",data[1]);
                $('tr#'+id+' > td > input.price').attr("value",data[2]);
        });

I just found the jQuery dump plug-in and it works really well. The
author of autocomplete plugin also has a troubleshooting
recommendation: console.log(arguments);    Navigating the DOM is my
latest frustration with java and jQuery. Today I finally figured out
the use of > in the selector.

Here is php code snippet serving the info... multiRow is my own
combination of mysql_query() and mysql_fetch_assoc()
<? // sku.php
$sql="SELECT sku, `desc`, FORMAT(price,2) AS price FROM item WHERE sku
LIKE '".$_GET['q']."%'";
$items=multiRow( $sql );
if( $items === FALSE ) {
        echo $sql." ".mysql_error();
}
elseif( is_array( $items ) ) {
        foreach( $items as $item ){
                foreach( $item as $field=>$val ){
                        $$field=$val;
                }
                echo "$sku|$desc|$price\n";
        }
} ?>

Reply via email to