Стивен, вы совершенно правы. Код:
alert(jQuery("select#city").val());
выполняется до того, как ваш запрос get () вернулся с ответом с сервера. Функция обратного вызова, которую вы определили для заполнения списка городов, не будет запущена, пока не будет получен ответ.
Попробуйте создать другую функцию для отображения вашего оповещения и вызовите ее из обратного вызова get:
jQuery('#country').live("change", function(){
populateCityListBox();
});
function showCity()
{
alert(jQuery("select#city").val());
}
- - - - - - - - - - - - - - -
function populateCityListBox()
{
jQuery.get("my/path/myfile.php", { instance: 'getCitiesByCountry', countryID: jQuery("select#country").val(), brandID: $_GET('brandID') },
function(data)
{
var options = '';
for (var i = 0; i < data.length; i++) {
if (i == 0)
options += '<option selected value="' + data[i].city + '">' + data[i].city + '</option>';
else
options += '<option value="' + data[i].city + '">' + data[i].city + '</option>';
}
jQuery("select#city").append(options);
showCity();
},"json");
}