I have some form input elements with class .commission_plan and different IDs. I need to sum up this element's values. I use this code:
jQuery(document).ready(function() {
var total = 0;
$('.commission_plan').each(function() {
total = total + parseFloat($(this).val());
});
$('#payment_total_amount_hidden').val(total);
$('#payment_total_amount').text('Total: ' + total);
}):
In my input fields are the values 3.45 and 4.65. But why does #payment_total_amount contain 8.100000000000001? Very strange behavior.
.map()returns an array, it really isn't appropriate here, since we're after a single value at the end of the loop.