Search code examples
javascriptajaxautosuggest

JavaScript Auto suggest to update multiple fields


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.


Solution

  • 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);
          ...
     });