Strategy: also use the class attribute to help you, for example, define the moneyInput class for each input (# 20_, # 50_, etc.).
Then use the following statement:
var c,sum=0;
$(".moneyInput").on("input",function(){
$("#"+this.id+"_").val(this.value*parseInt(this.id));
$(".moneyInput").each(function(){
sum+=parseInt($(this).val());
});
$("#total").val(sum);
});
And delete all your events that were previously defined.
source
share