views:

192

answers:

1

Hi,

I am using the jQuery autocomplete plugin for a smart input box. I want the first parameter in the input box to be autocompleted from one dataset, then once that has been selected change the dataset for the second parameter.

So if I have the following:

    var foo = ['a','b','c'];
    var bar = ['x','y','z'];

    $("#input_box").autocomplete(
        foo, { multiple: true, multipleSeparator: " "}
            );

I want to be able to dynamically change the 'foo' dataset to 'bar' after the first parameter has been autocompleted.

Any ideas how to do this?

A: 

Try:

var fubar = foo;
$("#input_box").autocomplete(
        fubar, { multiple: true, multipleSeparator: " "}
            ).live('keyup', function() {
               if($(this).val().length > 1)
                      fubar = bar;
               else   fubar = foo;
});

//EDITED, forgot .length which is key :)

bobsoap