$(document).ready(function(){ function countryChanged() { var CountryID = $("#edit-CountryID").val(); var CountryIDs = [2,3,8,9,10,12,15,24,203,45,47,48,53,54,55,73,83,87,90,98,101,106,110,112,120,127,131,136,140,143,149,151,153,156,159,161,162,166,175,179,181,183,1,190,194,200]; if($("#edit-displayOther").attr('checked')) { $("#edit-CountyID").attr("class","noshow"); $("#edit-otherCounty").attr("class","show"); }else { $.post("/php/countriesCounties.php","output=TRUE&type=counties&CountryID="+$("#edit-CountryID").val(),function(msg,textStatus) { if(msg) { blankOption = ''; msg = blankOption + msg; $("#edit-CountyID").removeClass("noshow"); $("#edit-CountyID").addClass("show"); $("#edit-otherCounty").attr("class","noshow"); var countyID = $("#edit-CountyID > :selected").val(); $("#edit-CountyID").html(msg); if(countyID) { $("#edit-CountyID > [value='" + countyID + "']").attr("selected", "selected"); }else $("#edit-CountyID").val($("#edit-CountyID > :first").val()); }else { $("#edit-CountyID").attr("class","noshow"); $("#edit-otherCounty").attr("class","show"); } },"html"); } } countryChanged(); $("#edit-CountryID").change(countryChanged); $("#edit-displayOther").change(countryChanged); $("#edit-displayOther").click(countryChanged); });