Skip to content

Instantly share code, notes, and snippets.

@aevans-mms
Last active August 28, 2023 21:18
Show Gist options
  • Save aevans-mms/ec091dd430809f0907ed8916329cec04 to your computer and use it in GitHub Desktop.
Save aevans-mms/ec091dd430809f0907ed8916329cec04 to your computer and use it in GitHub Desktop.
// parse_options.js
function parse_options(locator) {
let options = [];
document.querySelectorAll(locator).forEach(option => {
console.log(option);
const value = option.getAttribute("value");
const text = option.text;
const key = text
.replaceAll(" ", "_")
.replaceAll(",", "_")
.replaceAll("-", "_")
.replaceAll("'", "_")
.replaceAll("/", "_")
.replaceAll("’", "_")
.replaceAll(".", "")
.replaceAll("(", "")
.replaceAll(")", "")
.replaceAll("&", "AND")
.toUpperCase();
options.push({
option: option,
key: key,
value: value,
text: text,
});
});
return options;
}
let locator = "select#country > option"; // <== change locator for each dropdown
const options = parse_options(locator);
let data = "";
options.forEach(option => { data += `${option.key}("${option.value}", "${option.text}")` + "," + "\n"});
console.log(data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment