Skip to content

Instantly share code, notes, and snippets.

@mphalliday
Created October 31, 2011 12:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mphalliday/1327432 to your computer and use it in GitHub Desktop.
Save mphalliday/1327432 to your computer and use it in GitHub Desktop.
Dependent jquery select lists
$(".country_selector").change( function(){
if ($(".region_selector").length > 0){
$.getJSON('/countries/'+$(this).val(), function(data) {
$(".region_selector").html($("<option></option>"));
$.each(data.country.regions, function(index, region){
$(".region_selector").
append($("<option></option>").
attr("value",region.id).
text(region.name));
});
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment