[Answered ]-Passing variables from HTML to Javascript file that uses addEventListener

1👍

Use data attributes. The way you’re currently doing it could theoretically work if you rigged it up just right, but it’s definitely not the best practice. An easy solution is:

Instead of this code,

<script>amount=parseInt("{{event.price}}")</script>

just attach a data-amount attribute to an element near the tree. You might even be able to get away with putting it on the payment-request-button like this:

<div id="payment-request-button" data-amount="{{event.price}}">

Then in your javascript:

//...
    amount: parseInt(document.querySelector("#payment-request-button").dataset.amount)
//...

If you can’t edit the javascript file then things are a lot more complicated, so I hope you can!

Leave a comment