Last active
August 19, 2016 15:33
-
-
Save salsalabs/8dfad8a81ae25964926a to your computer and use it in GitHub Desktop.
Remove states from the State dropdown.
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
<script type="text/javascript"> | |
// Script to remove states from a State dropdown. There are special options | |
// to remove Canadian provinces, armed forces codes and the "other" option. | |
// @see https://salsasupport.zendesk.com/entries/66692524 | |
// | |
// You configure this. Change the list of states to includes the ones that you | |
// do not want to appear in a States dropdown. Here are the rules: | |
// | |
// 1. States are two letters. | |
// 2. Separate the states with spaces. | |
// 3. Only uses letters and spaces. | |
// 4. Do not disturb the punctuation. It bites when you try to touch or feed it. | |
// | |
// Here's how to remove Oklahoma, Iowa and Nebraska. | |
// | |
// STATES = "OK IA NE"; | |
// | |
var STATES = ""; | |
// Set change "false" to "true" in this line to show only US states. | |
//This setting overrides the other settings (below). | |
var US_STATES_ONLY = false; | |
// These are predefined lists that you can remove. Their names are | |
// are clues about what they remove. If you want to remove any of | |
// these, change 'false' to 'true'; | |
// | |
var CANADIAN = false; | |
var ARMED_FORCES = false; | |
var US_TERRITORIES = false; | |
var OTHER = false; | |
document.addEventListener('DOMContentLoaded', function() { | |
var toBeRemoved = STATES; | |
if (US_STATES_ONLY || CANADIAN) { | |
toBeRemoved = toBeRemoved + " AB BC MB NB NF NL NS NT NU ON PE QC SK YT"; | |
}; | |
if (US_STATES_ONLY || ARMED_FORCES) { | |
toBeRemoved = toBeRemoved + " AA AE AP"; | |
} | |
if (US_STATES_ONLY || US_TERRITORIES) { | |
toBeRemoved = toBeRemoved + " AS GU MP PR VI"; | |
} | |
if (US_STATES_ONLY || OTHER) { | |
toBeRemoved = toBeRemoved + " ot"; | |
} | |
toBeRemoved = toBeRemoved.split(' '); | |
var stateSelects = document.getElementsByName('State'); | |
if (stateSelects.length == 0) return; | |
var select = stateSelects[0]; | |
var options = select.getElementsByTagName('option'); | |
if (options.length == 0) return; | |
for (var i = options.length - 1; i >= 0; i--) { | |
if (toBeRemoved.indexOf(options[i].value) != -1) { | |
select.removeChild(options[i]); | |
} | |
} | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment