jk1844
jk1844

Reputation: 327

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>

Upvotes: 0

Views: 685

Answers (2)

Oscar Jara
Oscar Jara

Reputation: 14187

I made this for you:

I also used a plugin for text events:

http://www.zurb.com/playground/javascripts/plugins/jquery.textchange.min.js

(to clean the short code when infection doesn't match with less code)

Live Demo: http://jsfiddle.net/oscarj24/SUckd/1/

Upvotes: 0

turankonan
turankonan

Reputation: 1009

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/

Upvotes: 2

Related Questions