Different redirect URLs after form submitted (Custom Form Embed Code)

Hey brilliant peers!

Looking for advice on adding custom javascript calls on Form Submissions in the form embed code on our website.
Goal: redirect the post-submission thank you page to different URLs based on the input fields upon form submission. (Variable landing pages)
I saw this post: https://community.hubspot.com/t5/Lead-Capture-Tools/Single-form-for-multiple-pages-multiple-thank-you-pages/m-p/494326/thread-id/6425
And read through this article: https://legacydocs.hubspot.com/docs/methods/forms/advanced_form_options
And built my first pass at the javascript code in our embed:
~~ start ~~

onFormSubmitted: function($form) {
if (
(
document.querySelector("input[name='customer_input_revenue']").value = "Over $500M"
)
) {
// if field value is a specific results, then set value of redirectUrl to a hardcoded URL I desire
redirectUrl.value = "https://aidaptive.com/nickbudincich-redirect-case-1" ;
return redirectUrl ;
} else {
// Otherwise, set value of redirectUrl to a default hardcoded URL I desire
redirectUrl.value = "https://aidaptive.com/nickbudincich-redirect-else" ;
return redirectUrl ;
}
}​

~~ end ~~
(see pic)
I’m sure this is super simple, it’s just a matter of syntax and I’m not a pro.
Is there someone who can point me to the right resource? Or someone who can comment on the right syntax?
The logic is straightforward:

  • Upon form Submitted >
  • IF ( field input is ___ )
  • THEN (set the redirect URL to case 1 )
  • OTHERWISE (set to default redirect URL)
    Thank you SO much!

Hey @nickbudjml

As someone with a huge amount of experience in HubSpot forms, I’d always recomend against customising the embed code tbh. Even the onFormSubmitted still runs the risk of redirecting the page before the HS submission happens. But if you need to do it you need to do it!

My Js is a bit rusty but this does seem very straightforward, visitors should be redirected to Aidaptive - Adaptive AI for Business if they input a value for the property “customer_input_revenue” of “over $500m” right?
I would expect this to work, but it’s impossible to troubleshoot why it’s not working without having an example, what exactly is happening that is unexpected when you do this? Do you have an example page of this not working as expected?