Programmatically form redirect without jQuery (onFormSubmit)

There is anyway to do programmatically redirect the same form across multiple pages without require jQuery lib?

Like this solution just without jQuery:

https://community.hubspot.com/t5/Content-Strategy-SEO/Creating-a-download-or-e-book-download/td-p/35430

Hey @ballonura

thank you for sharing this. I’ll tag a few experts that could help you.

Hey @stefen @SandyG1 @Jsum any thoughts you can share with @ballonura?

Thanks

Sharon

Thx @sharonlicari , i’ll w8.
16x16_smiley-very-happy.png.png

@ballonura sure, you can use vanilla js to programatically redirect a user to a new page. Here’s an example that checks if the user submitted the form with a phone number and redirects to different pages depending on that:

<script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/v2.js"></script>
<script>
hbspt.forms.create({
portalId: "xxxxx",
formId: "xxx-xxx-xxx",
onFormSubmit: function() {
 var phone = document.querySelector('[name="tel"]').value;
 if(phone) {
 window.location.href = "http://exammple.com/ty-we-will-call-you";
 } else {
 window.location.href = "http://exammple.com/ty-we-will-email-you";
 }
 }
});
</script>