jquerylistautocomplete

Using Autocomplete populate more than one field


I am trying to implement auto complete via jquery auto complete plugin. I have used the script from here jQuery UI autocomplete. I currently have a field called 'Search Infections' where I am storing the 'Description'.

<tr>
<td>Search Infection</td>
<td>
<input id="tags" type="text"  size="80" /></td>
</tr>

this works fine for autocomplete.

I also have a field called 'Short code' in which I want to store the Code.

<tr>
<td>Short Code</td>
<td>
<input id="" type="text"  size="15" /></td>
</tr>

Is there a way I could store the code in the 'short code' field when a user search the Description in the infection field?

Please, please help.

  CODE and DESCRIPTION list.

  ---------------------------------------------------------
  Code  Description
  ---------------------------------------------------------
  ID01  Actinomycosis
  ID02  Aspergillosis
  ID03  Bacteraemia / blood stream infection/ Septicaemia
  ID04  Bacterial meningitis
  ID05  Bronchiectasis
  ID06  Candidiasis
  ID07  Carotid patch infection
  ID08  Cellulitis
  ID09  Cerebral abscess
  ID10  Cholangitis
  ---------------------------------------------------------------------
  =====================================================================

  <script>
  $(function() {
    var availableTags = [
                  "Actinomycosis",
                  "Aspergillosis",
                  "Bacteraemia / blood stream infection/ Septicaemia",
                  "Bacterial meningitis",
                  "Bronchiectasis",
                  "Candidiasis",
                  "Carotid patch infection",
                  "Cellulitis",
                  "Cerebral abscess",
                  "Cholangitis" 
                    ];
    $( "#tags" ).autocomplete({
        source: availableTags
    });
});
</script>

Solution

  • Try to this link.

    That's sample code is :

    var availableTags = [
        {key:"ID01",value:"Actinomycosis"},
        {key:"ID02",value:"Aspergillosis"},
        {key:"ID03",value:"Bacteraemia / blood stream infection/ Septicaemia"}
    ];
    

    http://jsfiddle.net/5EsAb/3/