Your code isn't working due to:
$(this.id).attr("value");
So this is saying $(yourElement)
instead of $('#yourElement')
Try:
var sum = 0
$("body").on("keyup", ".user_defined", function() {
sum = 0;
$(".user_defined").each(function() {
sum += parseFloat($(this).val());
});
$("#totalDonation").val(sum);
});
Also considering you're doing this on every key up, I'd remove the slow .each
and do:
var sum = 0;
var $userDefined;
$("body").on("keyup", ".user_defined", function() {
sum = 0;
$userDefined = $(".user_defined"); // This can go outside the keyup if this list will never change.
for(var i = 0; i < $userDefined.length; i++) {
sum += parseFloat($userDefined[i].val());
}
$("#totalDonation").val(sum);
});