Hey guys I have a table with a couple of checkboxes, all of those checkboxes have a numeric value in a hidden input next to them. I would like to display the sum of those in a input text at the bottom of my little table. I came as far as the script bellow but it turns out my JS and JQuery knowledge is (way?) to minimal. Any clue to what the best approach to this is?
<td>
<input checked="checked" type="checkbox" class="processPaymentProducts" name="processPaymentProducts[]" value="<?=$transaction['student_transaction_id']?>" />
<input type="hidden" id="prodPrice[<?=$transaction['student_transaction_id']?>]" name="prodPrice[<?=$transaction['student_transaction_id']?>]" value="<?=($transaction['student_transaction_amount_min']*100)?>" />
</td>
<script>
$(document).ready(function() {
$(".processPaymentProducts").click(function(){
var amount;
$amount = 0;
jQuery.each($(".processPaymentProducts:checked").val(), function() {
$amount += $(this).next('input').val();
console.log($(this).next('input').val());
});
if($amount>100) { $amount = $amount/100; } else { $amount = 0; }
$('#processPaymentAmount').val($amount);
});
});
</script>