1

I am currently using this for a single autocomplete box (id="drug"), and it works beautifully. I need to have a second autocomplete box (id="drug2") that uses the same array as its choices. I cannot seem to get it to work at all. Every time I try to modify the code I break it on the both. I'm sure someone out there has an elegant solution that will lead me in the right direction . . .

<script type="text/javascript">
function findValue(li) {
 if( li == null ) return alert("No match!");

 // if coming from an AJAX call, let's use the DrugId as the value
 if( !!li.extra ) var sValue = li.extra[0];

 // otherwise, let's just display the value in the text box
 else var sValue = li.selectValue;

 //alert("The value you selected was: " + sValue);
}

function selectItem(li) {
 findValue(li);
}

function formatItem(row) {
 return row[0] + " (id: " + row[1] + ")";
}

function lookupLocal(){
 var oSuggest = $("#drug")[0].autocompleter;
 oSuggest.findValue();
 return false;
}

$(document).ready(function() {
 $("#drug").autocompleteArray(

  ['Acyclovir','Amikacin','Aminophylline','Amiodarone','Ampicillin','Atropine','Azithromycin','Aztreonam','Bupivacaine','Calcium Chloride','Calcium'],
  {
   delay:10,
   minChars:1,
   matchSubset:1,
   onItemSelect:selectItem,
   onFindValue:findValue,
   autoFill:true,
   maxItemsToShow:100
  }

 );
});
</script>
4

1 回答 1

2

您可以在 jQuery 调用中使用多重选择器,然后在其上调用您的 autocompleteArray:

$(document).ready(function() {
 $("#drug1, #drug2").autocompleteArray(
  ['Acyclovir','Amikacin','Aminophylline','Amiodarone','Ampicillin','Atropine','Azithromycin','Aztreonam','Bupivacaine','Calcium Chloride','Calcium'],
  {
   delay:10,
   minChars:1,
   matchSubset:1,
   onItemSelect:selectItem,
   onFindValue:findValue,
   autoFill:true,
   maxItemsToShow:100
  }    
 );
});
于 2010-10-11T13:47:10.340 回答