Call JS Function from Button

Hey Guys. Should be easy but not working for me so looking for some help as to why not.

EXPECTED RESULTS:
Hit button >> Run Function getCartData()

SETUP

<button id="btn-cart-data" class="btn small" style="width: auto !important;" onclick="getCartData()">Get Cart Data</button>

getCartData() Function is located in the Head of the Page as a script

RESULT
Button does not actually run function (tried with both flows & static events) but the function does work if I call it directly from the console in the browser.

Any thoughts on this?

See quick video to show…

It’s not a dmx-button. So remove that attribute is=“dmx-button” and move your Javascript function tothe end before the

I think, maybe, your function is returning the array when the button is clicked but doing nothing with it. To find out you could try:

onclick="var gcd = getCartData(); console.log(gcd);"
1 Like

This works! Awesome and thanks for your help with this one!