views:

161

answers:

1

Okay, I have been messing with this autocomplete stuff for 2 weeks now, and it's starting to give me a headache! I've gotten it to do almost everything I need, but I'm hung up on one issue. I have two autocomplete text inputs that are tied together. The first input allows the user to select a person from a MySQL database table. Then, based on that selection, the second input allows the user to select one of the person's addresses from an addresses database table. This part all works fine.

The problematic autocomplete field queries an addresses table and stores each result in an array slot as follows:

title|street_address|city|state|zip

The trouble comes when simply trying to output the selected item's data to the innerHTML of a SPAN tag.

I've used the formatItem option to only display the title in the autocomplete list. Upon selecting the item I want it to then show the street_address, city, state and zip in a SPAN tag below the input box. It's getting the information, but since the formatItem function automatically reads through every row, it is displaying the street_address, city, state and zip of the last item in the list instead of the one that is selected. However, what is returned to the text input is the title of the selected item. It's very frustrating!

Does anyone know how I can get this issue sorted out???

Thanks in advance for any help!

A: 

I'm assuming you're using http://code.google.com/p/jquery-autocomplete/ or one of the variants. What you need to do is attach an event to onItemSelect. In older versions you'd get the LI element and an optional extra array of data. In the most recent version (after the rewrite), you get the standard value and optional data response. If you're confused, just start out with this setting (assuming Firebug or othe provider of console.log):

...
onItemSelect = function(a, b) { console.log(a); console.log(b); }
...

This will show you the response of the version you are using. You can work from there.

Let me know if you can get it to work. If you run into problems, I'll write a more complete example.

dyve