I am currently having trouble with implementing a JavaScript to enable commas to the currency fields, and performing a calculation with them. When enabled the commas function, the calculation only calculate after the commas from the currency fields. Any suggestion is appreciated, thanks.
$(document).ready(function () {
$('.table').on('blur', 'input', sumtotal)
$('#q17').on('blur', 'input', sumtotal)
$('#q25').on('blur', 'input', sumtotal)
//product table function
function sumtotal() {
$('.total input').attr('readonly', false);
var quantity = 0;
var unit = 0;
var total = 0;
var subtotal = 0;
var shipping = $('#q25 input').val();
var gradtotal = 0;
$('.table.cf-table-block tbody tr').each(function () {
quantity = parseNumber($(this).find('.quantity input').val());
unit = parseNumber($(this).find('.unit input').val());
subtotal = parseNumber(quantity * unit);
$(this).find('.total input').val(subtotal.toFixed(2));
total += subtotal;
});
grandtotal = parseNumber(shipping)+parseNumber(total)+(total*$('#q17 input').val());
$('#q26 input').val(grandtotal);
//added to force a change call. Currently if an alert is placed into the function it fires off but no formatting
$('#q26 input').change();
}
//parse for number value function
function parseNumber(n) {
var f = parseFloat(n); //Convert to float number.
return isNaN(f) ? 0 : f; //treat invalid input as 0;
}
});
$(document).ready ( function(){
$('[id=Field2]').click(function(){
var test = $('select[id=Field20] option:last-child').text()
$('[id=Field1]').val(test);
});});
$(document).ready(function () {
$(".total input, .etotal input, .shipping input").attr("pattern", '^(\\d+|\\d{1,3}(,\\d{3})*)(\\.\\d{2})?$');
$(".total input, .etotal input, .shipping input").on("change", function () {
$(this).val($(this).val().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,"));
});
});