Jim, >I've got an autocomplete field (based on Jörn Zaefferer's plugin) which >works great. > >I'm using it to grab a user from a database. > >What I need to do now is after the user selects their choice from the >dropdown - I need to return to the db and grab more info based on their >choice (address, etc). > >Or can I somehow return that data with the original query? Not sure which >would be best performance wise... > >Still getting my feet with with Ajax and not sure the best way to do this - >looking for advice and suggestions :)
This is actually pretty easy to accomplish. If you're only passing back a few pieces of information, you could pass the data back with the autocomplete matches. The advantage of this is you don't have to do another lookup. The disadvantage, and it can be a big one, is that you can really increase the amount of data required to be sent on each lookup. If there's a lot of matches and a lot of data you're passing back, this can be problematic for several reasons (memory consumption in the browser and bandwidth issues.) Either way you decide to solve the problem (either sending it with your original match or by doing an additional AJAX call) is going to be handled in similar ways. The way you handle this is by using the result() callback function. Go to: http://dev.jquery.com/browser/trunk/plugins/autocomplete/index.html Look at lines 100-103. This shows off how a callback was configured to run when a value was selected for the "Multiple Birds (remote):" field. If you're passing back multiple items in the AJAX lookup script, the "data" argument actually be an array of all the items for the selected item. You could use this method for populating data. The other option would be just to do your other AJAX call within the result() callback. You can use the "data" argument once again to get the primary key for the record you want to get and then just issue a simple AJAX call to retrieve the data you want. -Dan