Hello,
I am attempting to use javascript to calculate subtotals, tax, totals and then make fields read only in Forms 10.1.
Classes:
This is working fine with the following java:
//Calculate Totals and Tax - START $(document).ready(function () { $('.cf-table-block').on('blur', 'input', sumtotal); $('.tax').on('blur', 'input', sumtotal); function sumtotal() { var sum = 0; $('.cf-table-block tbody tr').each(function () { var s = 0; s = parseNumber($(this).find('.price input').val()) * parseNumber($(this).find('.quantity input').val()); $(this).find('.cost input').val(s); //$('.cost input').attr('readonly', 'True'); //makes the field read only after we give it a value. sum += s; $('.subtotal input').val(sum); $('.subtotal input').attr('readonly', 'True'); //makes the field read only after we give it a value. $('.tax input').val(parseNumber($('.taxpercent input').val())*sum); $('.tax input').attr('readonly', 'True'); //makes the field read only after we give it a value. $('.total input').val(parseNumber($('.tax input').val())+sum); $('.total input').attr('readonly', 'True'); //makes the field read only after we give it a value. $('#q83 input').attr('readonly',true); $('#q83 select').attr('disabled',true); }); } function parseNumber(n) { var f = parseFloat(n); //Convert to float number. return isNaN(f) ? 0 : f; //treat invalid input as 0; } }); //Calculate Totals and Tax - END
I then added this code under the code above:
//Keep all currency fields at two decimal places - START $(document).ready(function() { $('.currency').change(function() { $(this).val(formatCurrency($(this).val())); }); function formatCurrency(value) { var float = parseFloat(value); return isNaN(float) ? 0 : (Math.round(float*100)/100).toFixed(2); } }); //Keep all currency fields at two decimal places - END
My result ends up being this: (only unit price gets the two decimal places)
How do I combine/change the code to get it to show two decimal places on all entries for "Unit Price", "Price/Cost", "Subtotal", "Tax" and "Total"?