Skip to content

Instantly share code, notes, and snippets.

Created June 2, 2009 12:44
Show Gist options
  • Save anonymous/122221 to your computer and use it in GitHub Desktop.
Save anonymous/122221 to your computer and use it in GitHub Desktop.
var states = new Array();
<% for region in @regions -%>
states.push(new Array(<%= region.parent_id || '-1' %>, '<%=h region.name %>', <%= region.id %>));
<% end -%>
$(document).ready(function() {
$('#ad_root_region_id').change(function() {
country_id = parseInt( $('#ad_root_region_id').val() );
var options = '<option></option>';
for (i=0;i < states.length;i++) {
if (country_id == states[i][0]) {
options += '<option value="' + states[i][2] + '">' + states[i][1] + '</option>';
}
}
$("#ad_region_id").html(options);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment