In a previous question i made Dynamic dependent select menus i posted this example code: http://jsfiddle.net/Bs5Db/50/.
This is the HTML version of the particular jquery script.
The user @jSweazy helped me pointing that i should update the jquery.uniform script every time i select a new state from the first menu.
The working version of the example is here: http://jsfiddle.net/Bs5Db/53/.
I know that the default option is too large for the menu but that is easily fixed….
My problem now is that i actually use the PHP version of the script. In that version updating the jquery.uniform with $.uniform.update(); doesnt do the trick. Actually the second menu isnt visible anymore when i insert the update command.
The PHP version is the following…
$(document).ready(function(){
function populate() {
if($('#state').val() == 'AK' || $('#state').val() == 'DC') // Alaska and District Columbia have no counties
{
$('#county_drop_down').hide();
$('#no_county_drop_down').show();
} else {
fetch.doPost('../getCounties.php');
}
}
$('#state').change(populate);
var fetch = function() {
var counties = $('#county');
return {
doPost: function(src) {
$('#loading_county_drop_down').show(); // Show the Loading...
$('#county_drop_down').hide(); // Hide the drop down
$('#no_county_drop_down').hide(); // Hide the "no counties" message (if it's the case)
if (src) $.post(src, { state_code: $('#state').val() }, this.getCounties);
else throw new Error('No SRC was passed to getCounties!');
},
getCounties: function(results) {
if (!results) return;
var allCounties = $("<option value=\"All\">All Counties</option>");
counties.html(results);
counties.prepend(allCities);
counties.val("All").attr('selected',true);
$('#loading_county_drop_down').hide(); // Hide the Loading...
$('#county_drop_down').show(); // Show the drop down
}
}
}();
populate();
});
The getCounties.php that is querying the database and retrieves the counties of each state works fine.
state and county are the names of the two select menus.
So if anyone can give me an advice of how to achieve the update of the counties menu in this version of the script i would be grateful.
Thanx in advance for taking the time to read!
I realized that even in this case you have to update the jquery.uniform but since there are other styled elements such as radio buttons, checkboxes etc.
You have to insert $.uniform.update(‘select’).So the last part of the code becomes…