Calculate Repeater Meta Box Input Field Values and Display Total

You need to loop through the values of each input and add them together. You can do this using a each.

Try this. Replace your calculate function with this.

calculate = function(){
    var total = 0;
    $('.wpp-repeater-input').each(function () {
        total += parseInt($(this).val());
    });

    document.getElementById('wpp_investment_total').value = parseInt(total);
}

On a side note: I would remove the ID on the input, you shouldn’t have multiple of the same IDs. Notice I used the class to target the inputs.

Leave a Comment