In the following code, how could I override the "donateAmount" variable whenever someone runs the click function?
In other words, whenever someone clicks, he removes everything that is inside the variable "donateAmount" and replaces the new sum val ().
thanks
UPDATE
This code below now works, thanks to fixing the problem with the variable scope.
$('label input').click(function () { if ($('label input').is(':checked')) { $(this).parent().addClass('checked'); $('.donate-now label').not($(this).parent()).removeClass('checked'); var donateAmount = $(".checked input").val(); } $('#click').click(function(){ if ($('label #other').is(':checked')) { donateAmount = $("#otherAmount").val(); } $('p').html(donateAmount); }); });
source share