Onclick Not Working

Highlighted
New Member
1 0 0

Hi All,

 

I have an onclick event I am trying to fire on the click of the checkout button on the cart-drawer snippet however this does not work. I think as this seems to control the form post it may take prioirty from my function or maybe i've written it wrong. Can someone please have a look at this for me. I am having trouble with the function GA_Begin_Checkout()

 

The site is https://miafratino.com/ and it should fire on the click of the checkout button at the cart pop out. 

 

Code:

 

<form class="Cart Drawer__Content" action="/cart" method="POST" novalidate>

<div class="Drawer__Main" data-scrollable>
{%- if settings.cart_show_free_shipping_threshold -%}
{%- assign threshold_in_cents = settings.cart_free_shipping_threshold | times: 100 -%}

<div class="Cart__ShippingNotice Text--subdued">
<div class="Drawer__Container">
{%- if cart.total_price >= threshold_in_cents -%}
<p>{{- 'cart.general.free_shipping' | t -}}</p>
{%- else -%}
{%- capture remaining_amount -%}<span data-money-convertible>{{ cart.total_price | minus: threshold_in_cents | abs | money_without_trailing_zeros }}</span>{%- endcapture -%}
<p>{{- 'cart.general.free_shipping_remaining_html' | t: remaining_amount: remaining_amount -}}</p>
{%- endif -%}
</div>
</div>
{%- endif -%}

{%- if cart.item_count == 0 -%}
<p class="Cart__Empty Heading u-h5">{{ 'cart.general.empty' | t }}</p>
{%- else -%}
<div class="Drawer__Container">
<input type="hidden" name="attributes[collection_mobile_items_per_row]" value="">
<input type="hidden" name="attributes[collection_desktop_items_per_row]" value="">

{% include 'cart-items' %}
</div>
{%- endif -%}
</div>

{%- unless cart.item_count == 0 -%}
<div class="Drawer__Footer" data-drawer-animated-bottom>
{%- capture shipping_and_taxes_notice -%}{{ 'cart.general.shipping_and_taxes_notice' | t }}{%- endcapture -%}

{%- if settings.cart_enable_notes or shipping_and_taxes_notices != blank -%}
{%- if settings.cart_enable_notes -%}
{%- if cart.note == blank -%}
<button type="button" class="Cart__NoteButton" data-action="toggle-cart-note">{{ 'cart.general.add_note' | t }}</button>
{%- else -%}
<button type="button" class="Cart__NoteButton" data-action="toggle-cart-note">{{ 'cart.general.edit_note' | t }}</button>
{%- endif -%}
{%- endif -%}

{%- if shipping_and_taxes_notice != blank -%}
<p class="Cart__Taxes Text--subdued">{{ shipping_and_taxes_notice }}</p>
{%- endif -%}

{%- if cart.cart_level_discount_applications != blank -%}
{%- for discount_application in cart.cart_level_discount_applications -%}
<p class="Cart__Discount">{%- include 'icon' with 'sale' -%} {{ 'cart.general.discount' | t }} ({{ discount_application.title }}): -<span data-money-convertible>{{ discount_application.total_allocated_amount | money_without_trailing_zeros }}</span></p>
{%- endfor -%}
{%- endif -%}
{%- endif -%}

<!-- Begin Checkout for GA -->
<script>
function GA_Begin_Checkout() {
gtag('event', 'begin_checkout', {
"items": [
{% for item in cart.items %}
{
"id": "{{ item.product.id }}",
"name": "{{ item.product.title }}",
"price": '{{ item.product.price | money_without_currency }}'
},
{% endfor %}
]
});
}
</script>
<button type="submit" onclick="GA_Begin_Checkout()" name="checkout" class="Cart__Checkout Button Button--primary Button--full">
<span>{{- 'cart.general.checkout' | t -}}</span>
<span class="Button__SeparatorDot"></span>
<span data-money-convertible>{{ cart.total_price | money_without_trailing_zeros }}</span>
</button>

{%- if settings.cart_enable_notes -%}
<div class="Cart__OffscreenNoteContainer" aria-hidden="true">
{%- if cart.note == blank -%}
<span class="Cart__NoteButton">{{ 'cart.general.add_note' | t }}</span>
{%- else -%}
<span class="Cart__NoteButton">{{ 'cart.general.edit_note' | t }}</span>
{%- endif -%}

<div class="Form__Item">
<textarea class="Cart__Note Form__Textarea" name="note" id="cart-note" rows="3" placeholder="{{ 'cart.general.note_placeholder' | t }}" data-scrollable>{{ cart.note }}</textarea>
</div>

<button type="button" class="Button Button--primary Button--full" data-action="toggle-cart-note">{{ 'cart.general.save_note' | t }}</button>
</div>
{%- endif -%}
</div>
{%- endunless -%}
</form>

 

 

 

 

0 Likes