tags:

views:

61

answers:

2

The first letter you enter creates a pull-down menu of all items in a database that start with that letter...

+2  A: 

Are you looking for autocomplete plugin?

RaYell
Yup, that's the one. Thanks!If I just have 3-5 words to complete against what would be the best way to get that dataset into autocomplete if I'm using PHP and can preload the data locally? i.e. how do I get the dataset so it looks like it's local to JS?
Sly
+1  A: 

Hi,

Using Plugins/Autocomplete/autocomplete, it seems you can use "local" data, directly into the JS code, ie without having to do an Ajax request to the server :

autocomplete( url or data, [options] )

url or data : String, Array
An URL pointing at a remote resource or local data as an array.

options (Optional) : Options
A set of key/value pairs that configure the autocomplete. All options are optional.

So, you need a way to convert the data you have on the PHP side to some Javascript array.


If you are using PHP >= 5.2, you can use the json_encode function to do that.

For instance, you can have this kind of PHP code :

$data = array(
    'first',
    'second',
    'third',
);

$js_array = json_encode($data);

echo "var my_list = {$js_array};";

And the output you'll get looks like this :

var my_list = ["first","second","third"];

Which declares an initializes some Javascript array containing the results ;; up to you to put that kind of code where it belongs ;-)

Have fun !

Pascal MARTIN