views:

553

answers:

2

I have a simple autocomplete field that spits out a bunch of suggested words and puts it in the suggest field. Is there an auto suggest code that can enter the selected text but also auto fill a range of other fields instead of the selected field?

For example, searching through a contacts list you type their name or address and it suggests options. On clicking one it automatically draws from the database the rest of the available contact details.

+2  A: 

You ought to be able to do this with the Autocomplete plugin. Add a result handler and use it to populate your other fields.

 $('div#result').result( function(e,data,formatted) {
      $(this).html(formatted);
      $('div#address').html(data.address);
      ...
 });
tvanfosson
Looks like the demos give examples of doing just this. Thanks.
Peter
+1  A: 

If you use Ajax.Autocompleter from script.aculo.us, you can override the afterUpdateElement function to do this for you. You could then make a call that could send back JSON like the following:

{ fields: ['first', 'second'],
  first: 'value',
  second: 'another value' }

and populate your form with something like:

for(field in json.fields)
  $(field).value = json.getAttribute(field);
Josh Matthews