How to run a JS Function on a Shopify Customer Form Submission?

I have Shopify customer form set up to get emails for our product recommendation quiz.

The issue I’m running into is the inability to run a function or redirect the user when they submit their email through the form (the native functionality is just refreshing the page with a success message)

I need to run the goToCart() function on form submit, and none of these method below work:

{%- form 'customer', class: 'quiz-form', onsubmit:'goToCart();'-%}

{%- if form.posted_successfully? -%}

{%- endif -%}
{%- endform -%}

Do you have solution?