# Sign Up Page - Javascript Redirect

**URL:** <https://community.hubspot.com/t/sign-up-page-javascript-redirect/69808>\
**Category:** CMS Development\
**Tags:** javascript, enterprise\
**Created:** [November 23, 2022, 1:01am UTC](https://community.hubspot.com/t/sign-up-page-javascript-redirect/69808 "2022-11-23T01:01:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![AenghasHP](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/aenghashp/32/81360_2.png) [@AenghasHP](https://community.hubspot.com/u/AenghasHP)\
**Post date:** [November 23, 2022, 1:01am UTC](https://community.hubspot.com/t/sign-up-page-javascript-redirect/69808/1 "2022-11-23T01:01:16Z")

</div>

Hi,

We’re looking at changing payment providers from ChargeBee over to Stripe. As a part of the swap over we need to change our sign up process, which I’ve begun on this page ([https://npaq.redunion.com.au/join2-2](https://npaq.redunion.com.au/join2-2))

Ideally, customers will fill in their details and based on which option they select for both Employment Status (employmentStatusMap) and Preferred Billing Schedule (billingScheduleMap) it will spit out the correct redirect for the member to pay.

For example, if you select Employment Status: Part Time and Billing: Annual it should redirect the user to upon form submission to: [Stripe Checkout](https://buy.stripe.com/aEU01Q8gug2y43CdQX)

I’ve tried to make this work with the code below, which I think is returning the URL successfully, but then isn’t redirecting properly:

const stripeRedirect = (employmentStatusMap && billingScheduleMap)  
if (employmentStatusMap === “Part Time (\<48hrs / fortnight)” && billingScheduleMap === “Annually”) {  
return window.location = “[Stripe Checkout](https://buy.stripe.com/aEU01Q8gug2y43CdQX)”  
} else {  
return window.location = “[https://www.redunion.com.au](https://www.redunion.com.au)”  
}  
window.location = stripeRedirect;

For context, this is all nested under an onFormSubmit so I believe it should fire when the form is submitted. It might be a bit of an ask, but any guidance on the matter would be much appreciated! Javascript kind of breaks my brain a little bit still.

---

<div class="post-metadata">

**Author:** ![Kevin-C](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/kevin-c/32/34570_2.png) [@Kevin-C](https://community.hubspot.com/u/Kevin-C)\
**Post date:** [November 23, 2022, 2:34am UTC](https://community.hubspot.com/t/sign-up-page-javascript-redirect/69808/2 "2022-11-23T02:34:05Z")

</div>

Hey @AenghasHP

JS can be a hurdle but you’re getting close!  
We might be missing some context, but I do think you can refactor your code just a bit to get it working.

1. First I might wrap the logic in a function, so I can use it later and/or scale the logic in the future.
2. Then call the function when needed.

[This pen might help!](https://codepen.io/kcornett/pen/ZERxzVW?editors=0011)

Also onFormSubmit will redirect regardless of the form passing validation. I would look at capturing the data in the onFormSubmit event, then listening for the onFormSubmitted event to confirm that the form is valid before performing the redirect.

Hope this gets you moving!
