I have used a jQuery script and some php code to generate two select menus.
One menu has states and the other regions. Once the states menu is changed the correspknding regions are loading.
My question is how to set a default value of “all cities”. The script automatically loads the
regions that finds in the mysql table so i cant find a way to do that.
I guess i have to change something on the script. Any ideas will be helpful.
$(document).ready(function(){
function populate() {
if($('#states').val() == 'AK' || $('#states').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 = $('#search_area');
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;
counties.html(results);
$('#loading_county_drop_down').hide(); // Hide the Loading...
$('#county_drop_down').show(); // Show the drop down
}
}
}();
populate();
});
You don’t mention if “All Cities” is in your DB or not so I’m assuming it is not. Also I’m not sure what you’re returning exactly so I’m going to assume that counties is a select input.
Untested answer but perhaps it will help.
After the county list is returned you can prepend the “All” option to the list, and then select it…The only other thing you’d have to do then is make sure whatever is handling this form on the server knows what to do with “All”.