Question

Form Condition Redirect


Badge

I’m working on adding a custom script so that depending on teh selection in a dropdown menu, the form directs to different websites. Here is what I have so far…..my drop down form field is titled a2 . . . .do I put $(“a2”).on….. in the script below? Wgat do I put for the “case” options? The actual selection? So if the choice says “Blue” . . . do I put ….. case ‘blue’: …..?

 

 

   <script>

$("#your_drop_down_id").on('change', function() {

switch ($(this).val()) {

case '#your_dropdown_field_id':
window.module.lp.form.data.url= "http://www.google.com";
break;
case '#your_dropdown_field_second_id':
window.module.lp.form.data.url= "http://www.bing.com";
break;
}

});

</script>

3 replies

Userlevel 4
Badge +1

@joshua.m.sells, you can update the script to properly handle the dropdown menu selections and redirect based on those selections. Here’s how you can do it:

1. Use the correct jQuery selector for your dropdown menu.
2. Update the `case` options with the actual values of your dropdown menu items.

Here’s the revised script based on your description:

<script>
$("#a2").on('change', function() {
switch ($(this).val()) {
case 'Blue':
window.module.lp.form.data.url= "http://www.example-blue.com";
break;
case 'Red':
window.module.lp.form.data.url= "http://www.example-red.com";
break;
// Add more cases as needed
default:
window.module.lp.form.data.url= "http://www.default-url.com";
break;
}
});
</script>

In this script:

- Replace `#a2` with the correct ID of your dropdown menu.
- Replace `'Blue'` and `'Red'` with the actual values from your dropdown options.
- Update the URLs to the ones you want to redirect to for each selection.

Make sure that the values in the `case` statements exactly match the values in your dropdown menu options.

Badge

I’m using the Smart Builder . .. . will this work with Smart Builder because I cannot seem to get it to work even when I upload the script.

Userlevel 4
Badge +1

@joshua.m.sells With smart builder, it won’t work. But it should work with classic builder. Why you’re using smart builder? If you need to do custom code, please use classic builder which is way more better than smart builder.

Reply