Hi,

There are two textboxes, one(id:sites) is to display a dropdown list when user input any letters, another(id:siteID) is to catch the value when selecting an item from dropdown list. see example at: http://jqueryui.com/demos/autocomplete/

Below is my code:

var siteNames =new Array("ASDA","Tesco","Boots");
var siteIDs =new Array(1,3,7);

for (i=0; i<siteIDs.length;i++){
                    $( "#sites" ).autocomplete({             
                        source: siteNames,
                        select: function() {$('#siteID').val(siteIDs[i])}
                    });
                 }

the result is siteID box got nothing. but if setting siteIDs[2], the siteID box will display 7. Thus, i think the problem is jquery can't work with Javascript.

Can anyone help me? Many thanks!

jQuery is javascript. What are you trying to get out of using Autocomplete? I see no correlation between the site id and the site names. Beyond that by initializing the autocomplete in an array like that you are resting the acutocomplete function for every value in the siteIDs array. Your final object will be :

$( "#sites" ).autocomplete({             
                        source: siteNames,
                        select: function() {$('#siteID').val(7)}
                    });