lera.cernolev of Help Center Snippets
1/21/2020 - 5:52 AM

Migrated - 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 -->