$(document).ready(function() { function countryChanged() { var CountryID = $("#edit-CountryID").val(); var CountryIDs = []; $.post("/php/countriesCounties.php", "output=TRUE&type=counties&CountryID=" + $("#edit-CountryID").val(), function(msg,textStatus) { if(msg) { blankOption = ''; msg = blankOption + msg; if ($("edit-CountyID").hasClass("noshow")) { $("#edit-CountyID").removeClass("noshow"); } if($("#edit-displayOther").length > 0) { $("#edit-CountyID").attr("class", "show"); $("#edit-otherCounty").attr("class","noshow"); $("#edit-displayOther").attr("checked", false); } var countyID = $("#edit-CountyID > :selected").val(); $("#edit-CountyID").empty().attr('style', '"width: 100px !important"').html(msg); if (countyID) { $("#edit-CountyID > [value='" + countyID + "']").attr("selected", "selected"); } else { $("#edit-CountyID").val($("#edit-CountyID > :first").val()); } } else { blankOption = ''; $("#edit-CountyID").empty().attr('style', '"width: 100px !important"').html(blankOption); if($("#edit-displayOther").length > 0) { $("#edit-CountyID").attr("class", "noshow"); $("#edit-otherCounty").attr("class", "show"); $("#edit-displayOther").attr("checked", true); } } }, "html"); } countryChanged(); $("#edit-CountryID").change(countryChanged); if($("#edit-displayOther").length > 0) { $("#edit-displayOther").change(countryChanged); $("#edit-displayOther").click(countryChanged); } });