Using JQuery Autocomplete using array and drop down list
<p>I am trying to create a script that will use JQuery's autocomplete text box to display county data from an array that has been filtered by state. State is a drop down list. So for example: if a user has selected "Illinois" for the state, based on the begging letters they type into the text box, autocompklete would give them the closest county name. I was successfully able to filter the array by state and then load the array with the correct data but I am having problems trying to load the array into autocomplete. Here is the code segment. Thanks much for your help:</p>

<pre><code>    &lt;body &gt;
    &lt;script type="text/javascript"&gt;


    function findCounties(State)
      {
var County = new Object();

var xmlhttp;
if (window.XMLHttpRequest)
{
    // code for IE7+, Firefox, Chrome, Opera, Safari

     xmlhttp = new XMLHttpRequest();
}
else
{
    // code for IE6, IE5
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}

if (xmlhttp != null)
{
    xmlhttp.open("GET","US_Counties.csv",false); // the false makes this synchronous!
    xmlhttp.send();
    var text = xmlhttp.responseText;

    // text contains the ENTIRE CONTENTS of the text file
    // you *could* just write those contents directly to the HTML output:


    // but you might want to process that one line at a time.  if so:
    var lines = text.split("\n");

    var cntCounty = 0;
        for (var n=0; n&lt;lines.length; n++)
        {
            if(lines[n].indexOf(State) &gt; 0){
                var line = lines[n];
                var populate = line.split(',');


                County[cntCounty] = populate[1];
                cntCounty++;

            }//IF
        }//for
    $(function() {
            var Counties = [{
         a_state: []
        };
        for(var i in County) {

        var item = County[i];

            Counties.a_state.push({ 
            "label" : item.County
        "value" : item.County`enter code here`
        });
    ];

  j$("#counties").autocomplete({
    source: Counties 
  }).data("autocomplete")._renderItem = function(ul, item) {
    return $("&lt;li&gt;").data("item.autocomplete", item).append("&lt;a&gt;" + item.label ++ "&lt;/a&gt;").appendTo (ul);
});
</code></pre>
