Created
June 24, 2013 22:56
-
-
Save nclundsten/5854476 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function filterProvinces(element, countryCode) { | |
$(element).val(0); | |
optGroups = $(element).data('options'); | |
$(optGroups).each(function(){ | |
var match = false | |
if ($(this).data('country_code') == countryCode) { | |
$(element).append($(this)); | |
} | |
}) | |
$(element).find('optgroup').remove(); | |
} | |
$(document).ready(function(){ | |
province = $("select[name=province]"); | |
opts = $(province).find('optgroup').each(function(){ | |
//zf2 doesnt allow non-standard option attributes.. hooray. | |
$(this).attr('data-country_code', $(this).children().val().substring(0,2)); | |
}); | |
console.log(opts); | |
$(province).data('options', $(opts)); //store as data val | |
$(province).find('optgroup').remove(); //remove the elements | |
$("select[name=country]").live('change', function() { | |
province = $(this).siblings("select[name=province]"); | |
val = $(this).val(); | |
filterProvinces(province, val) | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment