Seo Cahill Seo Cahill - 1 year ago 134
CoffeeScript Question

Setting data attribute on stripe button

I can't figure this out. I checked other questions regarding setting data attributes, seems to be a tricky enough thing.

The stripe button amount is purely for aesthetics, I'm trying to set it ('data-amount') each time a user updates the quantity select box.

Every time I change the quantity select an alert gives the correct amount and if I inspect the dom the 'data-amount' attribute appears to be set correctly but when I click the stripe button the modal shows the default data-amount, i.e nothing.

Anyone know how to do this?

view (form, select input not shown)

<div class="stripe-controls" align="center">
<script src="" class="stripe-button"
data-key="ENV['STRIPE_PUBLIC_KEY'] %>" data-amount="">


$ ->

orderTotal = ->
quantity = $('#order_quantity').val()
price = $('#ticket-price').data('url')
total = quantity * price
$('.stripe-button').attr('data-amount', total)
alert total

Answer Source

Specify a custom amount using

Note: I work at Stripe.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download