Skip to content

Instantly share code, notes, and snippets.

@salsalabs
Last active August 17, 2018 20:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save salsalabs/1e44ac77a1a90df654e8 to your computer and use it in GitHub Desktop.
Save salsalabs/1e44ac77a1a90df654e8 to your computer and use it in GitHub Desktop.
Script to set a default country code in a donation page. See https://salsasupport.zendesk.com/entries/23475564-Set-a-default-country-for-a-donation-page.
<!-- BEGIN script to change the default country code and save a selected state value. -->
<script type="text/javascript">
document.addEventListener("DOMContentLoaded", function () {
var state = document.querySelector("select[name=State]");
var savedState = (state !== null) ? state.value : null;
var country = document.querySelector("select[name=Country]");
if (country != null) {
if (country.value == "") {
country.value = "US";
}
country.addEventListener("change", function() {
if (state != null && savedState != null) {
state.value = savedState;
}
});
}
});
</script>
<!-- END script to change the default country code and save a selected state value. -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment