Calculate Repeater Input Field Values and Display Total
-
I have a repeater custom meta box for my custom post type. I am new to Javascript and can not figure out how to calculate the value for each repeated input field and display the total combined. I have it functioning for the first input field, but it won’t calculate the value of all. Here is the code I am working with.
<script> var $ =jQuery.noConflict(); $(document).ready(function() { var count = <?php echo $c; ?>; $(".wpp-item-add.investment").click(function() { count = count + 1; $('#investment_here').append('<div class="wpp-repeater-wrapper">Title: <input class="wpp-repeater-input" type="text" name="investment['+count+'][title]" value="" placeholder="e.g. Web Design" />Amount: <input class="wpp-repeater-input" id="wpp-amount-value" type="text" name="investment['+count+'][investment_item]" value="" onblur="calculate()" placeholder="e.g. 2500" /><span class="wpp-item-remove investment">Remove</span></div>' ); return false; }); $(".wpp-item-remove.investment").live('click', function() { $(this).parent().remove(); }); }); calculate = function() { var resources = document.getElementById('wpp-amount-value').value; document.getElementById('wpp_investment_total').value = parseInt(resources); } </script>
The solution I am looking for: If I click Add Item and have 5 input fields, it would calculate the value of each field and have the total go to the field #wpp_investment_total.
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Calculate Repeater Input Field Values and Display Total’ is closed to new replies.