Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change button attribute on click before link fires

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?

like image 417
quantumpotato Avatar asked Mar 26 '26 02:03

quantumpotato


1 Answers

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/

like image 104
m3div0 Avatar answered Mar 28 '26 15:03

m3div0



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!