Form redirect URL based on dropdown select

Hi everyone,

I’m trying to redirect a user to a different page after submitting a form based on their selection from a dropdown:

My dropdown is countries, and based on what country the user select, I want him to be redirected to that country-specific page, for example, if the user selects Canada from the dropdown, he should be redirected to mywesbite.com/country/canada note that country is a CMS collection.

My form ID is wf-form and my dropdown field ID is country

  1. what kind of custom code to use here?

Thanks in advance

You should hire freelancer to solve this idea.

The idea ±

0-Event: After form submit (No API for this idea).

1-Get the select value:
https://stackoverflow.com/questions/17996523/javascript-store-html-select-as-a-variable

var varFromSelectMenu = document.getElementById("selected2").value;

2-Create var:
var redirectURL = "/country/"+varFromSelectMenu

3-And replace location with the value from step 2:
window.location.replace(redirectURL);

1 Like

Thanks, I guess that’s too complicated for me, there was an answer to a similar problem in this post and I am hoping to get the custom code for my case
similar issue

more on javascript…url redirect

I came across this issue earlier today.
This solved it -

<script>
console.log("1");
$('#form').submit(function() {
console.log("insideofform")
const selectedValue = $('#field').val();
switch (selectedValue) {
  case 'choice-1':
window.location = "URL"
    break;
  case 'choice-2':
 window.location = "URL"
    break;
  default:
window.location = "URL"
}

	});
</script>


1 Like

Hi, can’t get this to work. My code looks like this:

<script>
	$('#culture-guide-form').submit(function() {
	const selectedValue = $('#company-size').val();
  switch (selectedValue) {
    case '1 to 99':
  window.location = "/page-1"
      break;
    case '100 to 249':
   window.location = "/page-2"
      break;
    default:
  window.location = "/page-3"
}
	});
</script>

Tried having this inside and outside of the form but it’s not working. I also removed the redirect URL from the form element. I just see the thank you message when the form is submitted.

Thanks!

as Ezra Siton stated above go hire a freelancer or reach out to him directly