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

carpedev
Tourist
6 0 1

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();'-%}
<label for="quiz_email_input">Email</label>
<input type="hidden" name="contact[tags]" value="sweatquiz">
<input
type="email"
name="contact[email]"
class="quiz_email_input"
value="{{ form.email }}"
autocorrect="off"
autocapitalize="off"
autocomplete="email"
>
<div class="next_button_background" style="text-align:center;">
<button type="submit" class="next_button" onclick="goToCart();" style="margin-bottom: 10px;">SEE RESULTS</button>
</div>
{%- if form.posted_successfully? -%}
<script>(function(){goToCart();})</script>
{%- endif -%}
{%- endform -%}

 

Reply 1 (1)

truemoroz
Shopify Partner
3 0 0

Do you have solution?