I'm using the following code to populate a 2nd select box with cities:
jQuery('#country').live("change", function(){
populateCityListBox();
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);
},"json");
}
Populating the list box works fine. But the alert does not output the new city (after country selection). Can this be a binding problem? I thought using $.live solved all this.
It looks like the alert() is triggered before the city list box is updated. What am I doing wrong?