I want to autocomplete a Cities text input, but only search for cities in the country that was previously selected. The code I have seems like it should work, but it's not sending the correct country value.
The form:
Country: <select name='country' id='country'>
<option value='US'>USA</option>
<option value='UK'>United Kingdom</option>
</select><br/>
City: <input type='text' name='city' id='city' />
The js:
$( "#city" ).autocomplete({
source: "searchCities/" + $('select#country option:selected').val(),
minLength: 2
});
The URL structure should be 'searchCities/UK?term=foo' and the SQL statement is searching for the value of 'term' where the country code is 'UK'. If I type in the URL manually, it works without a problem (limiting to only the country)... and the autocomplete works in the form. However, it returns ALL cities without limiting by the country code.
Is there something I may be missing? Or maybe a better way to accomplish this? Thanks!