I'm not aware of any web service that would provide country/state/city listings but I suppose they probably exist since this is really an every day rather common scenario.
I will provide information about your second problem. And that are related dropdowns.
Related drop downs are always tricky and best done when loading is done on the client without full page postbacks. But in the end it always boils down to the complexity and amount of your data that fills them.
Not much data
When you have something like 10-50 items in first drop down and for each of them another 10-50 items for the second drop down, we can say that you don't have much data. Or when there are more than two drop downs we can say that we don't have much data when there are less than x000 records all together (do some testing in various browsers to get some acceptable limit). In this case you could provide all this data in your HTML preloaded and Javascript can use that when user interacts with these fields.
I would do it this way. I would generate JSON on the server and provide it in my HTML as:
var qualifications = {
"Manager": ["First", "Second", ...],
"Developer": ["...", ...],
...
};
Then I'd either prepopulate my fist drop down on the server or populate it on the client side on page load (in jQuery that would be by using $(function(){...});
). Handling change
event would then populate the second drop down by using array in specialities
that are part of the associative object described above (I'm using associative object instead of an array because it will be much easier to find corresponding specialities array to populate my second drop down by simply doing:
$("#FirstDropDown").change(function(){
var specialities = qualifications[$(this).val()];
...
});
Lots of data
When we have lots of data (or frequently changing data) in each drop down it's not feasible to load them all upfront. It's only feasible when we have some user interface process when users usually select many combinations (so we would eventually load 90% of all data). Anyway.
- preload the first drop down on the server (or on the client on page load)
attach a client side event to this first drop down, that issues an Ajax request to get the second drop down list data:
$("#Country").change(function(){
$.ajax({
type: "GET",
url: "Geo/GetStates",
data: $(this).val(),
success: function(data){
// populate states dropdown
},
error: function(xhr, state, err){
// display alert or something
}
});
});
when data from the server is returned we can populate our second drop down and attach a similar behaviour on its change
event.
- Do a similar thing for the next drop down
This way we get fast page responses due to loading only a handful of data.