You can use an array of objects, e.g.

var choices= [
  { name: "foo", id: "1" },
  { name: "bar", id: "2" },
  { name: "baz", id: "3" }
];

Your autocomplete callback might look like this

function MyAutoCompleteCallback (event, data, formatted) {
        $("#my_hidden_fld").val(data.id);
        ...
}




On Mar 23, 5:58 pm, Nick <njor...@gmail.com> wrote:
> Hello,
>
> I am attempting to use the autocomplete plugin to allow users to pick
> a text value from an input box and have the db id of that value
> populated to a hidden field that can then be posted back to the
> application.  I have this working fine with a url data source, but am
> confused how to do it with a JS array.
>
> Here is what I have:
>
> $("#suggest").autocomplete("/dev/autotest.php")
>   .result(function (evt, data, formatted) {
>     $("#sugghidden").val(data[1]);
>
> });
>
> Again, this works fine as autotest.php returns data in the format of:
>
> Something|1
> Another|2
> Test|3
>
> My question is in what way can I format the data if it is passed as an
> array and still populate the hidden form?
>
> Thanks.

Reply via email to