So I have my form pretty much done and I need to calculate the total values of input fields after AJAX fills them based on user selects. I have tried and tried and tried to find a solution but nothing is working... ugh.
Here's the html for the input fields that need to be calculated and the field that the sum needs to be returned to:
<input type="text" class="form-control prices" id="lt1total" placeholder="Amount" value="" readonly>
<input type="text" class="form-control prices" id="lt2total" placeholder="Amount" value="" readonly>
<input type="text" class="form-control prices" id="lt3total" placeholder="Amount" value="" readonly>
<input type="text" class="form-control disabled" id="lttotal" placeholder="Amount" value="" readonly>
Here is the AJAX request (there is one for each they all work correctly):
$.ajax({
method: 'GET',
url: 'example.url',
data: {
lt1datetype: lt1datetype,
lt1tt: lt1tt,
}
}).done(function(result) {
console.log('', result);
$('#lt1total').val(result);
});
And this is the only jquery function that I have gotten to even put a value for #lttotal :
$(document).ready(function() {
var sum = 0;
$(".prices").each(function(){
sum += Number($(this).val());
});
$("#lttotal").val(sum);
});
It only outputs 0 for the amount. The values that AJAX is getting are like this 123.00 or 1234.00 I'm stuck and aggravated. Any help or direction would be greatly appreciated.