I'm using the Dwolla platform with my site. I want to change the data-amount attribute of the button to the value in another text field on click. By the time the Dwolla site loads though, it prompts me to pay for the original, default amount so I take it my attribute modification is not happening.
<script type='text/javascript'>
$('.dwolla_button').click(function(){
alert($('#id_support_amount').val());
$('.dwolla_button').attr('data-amount', $('#id_support_amount').val());
});
</script>
I'm using a compressed javascript from Dwolla which fires the request when the button is clicked, so I may end up having to ask them / dig around in that.
How would I normally change the attribute before the link fires?
To do something before actual click, you should use
mousedown
handler.Try something like this:
$(document).on("mousedown",".dwolla_button", function(){ $(this).attr('data-amount', $('#id_support_amount').val());
});
or look at my working example http://jsfiddle.net/ZMb3E/1/