Skip to content

Instantly share code, notes, and snippets.

@dan-donica
Created July 19, 2023 09:54
Show Gist options
  • Save dan-donica/44379c41b737d8d45961c3b04f8fde13 to your computer and use it in GitHub Desktop.
Save dan-donica/44379c41b737d8d45961c3b04f8fde13 to your computer and use it in GitHub Desktop.
HC || Redirect depending on dropdown
<!-- Begin "Redirect depending on dropdown" || Help center -->
<!-- Insert in Settings->Javascript->Header -->
<!-- CS:20200120-11-1 -->
<script>
document.addEventListener("DOMContentLoaded", function() {
var dropdownName = "My Dropdown"; // Field name
var options = {
"Option 1": "https://instapage.com", // Each option on a new line
"Option 2": "https://help.instapage.com/hc",
"Option 3": "https://help.instapage.com/hc/en-us/articles/214133067"
// "Option Name" : "Redirect URL if this option is chosen"
}
var selectInput = document.querySelectorAll('form select[name="' + dropdownName + '"]');
window.instapageFormSubmitSuccess = function() {
for (var i = 0; i < selectInput.length; i++) {
var selectedOption = selectInput[i].value;
document.querySelectorAll('input[name="redirect"]')[i].value = options[selectedOption];
}
}
});
</script>
<!-- End "Redirect depending on dropdown" || Help center -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment