Skip to content

Instantly share code, notes, and snippets.

@nclundsten
Last active December 18, 2015 22:29
Show Gist options
  • Save nclundsten/5854944 to your computer and use it in GitHub Desktop.
Save nclundsten/5854944 to your computer and use it in GitHub Desktop.
(function($) {
function countryProvinces(province, country)
{
//zf2 select options dont allow non-standard attributes.. hooray.
opts = $(province).children('optgroup').each(function(){
$(this).attr('data-country_code', $(this).children().val().substring(0,2));
});
$(province).data('options', opts);
$(province).children('optgroup').remove();
$(country).data('province', province);
updateProvince = function(province, countryCode) {
$(province).val(0)
$(province).children('optgroup').remove();
$(province).data('options').each(function(){
if ($(this).data('country_code') == countryCode) {
$(province).append(this);
}
})
}
//on change of country, update province element to show provinces that match the country
$(country).change(function() {
updateProvince($(this).data('province'), $(this).val());
});
updateProvince(province, $(country).val());
}
}) (jQuery)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment