I want to display values in text inputs that are in "dollar format"; IOW, instead of "10.5" I want it to be "10.50"
I was able to do that in the grand total box like so (last line of code):
$(document).on("blur", '.amountbox', function (e) {
var amount1 = $('[id$=boxAmount1]').val() != '' ? parseFloat($('[id$=boxAmount1]').val()) : 0;
var amount2 = $('[id$=boxAmount2]').val() != '' ? parseFloat($('[id$=boxAmount2]').val()) : 0;
var amount3 = $('[id$=boxAmount3]').val() != '' ? parseFloat($('[id$=boxAmount3]').val()) : 0;
var amount4 = $('[id$=boxAmount4]').val() != '' ? parseFloat($('[id$=boxAmount4]').val()) : 0;
var amount5 = $('[id$=boxAmount5]').val() != '' ? parseFloat($('[id$=boxAmount5]').val()) : 0;
var grandtotal = amount1 + amount2 + amount3 + amount4 + amount5;
$('[id$=boxGrandTotal]').val(parseFloat(grandtotal).toFixed(2));
});
That working, I thought maybe I could get the individual "amount" boxes to work similarly by doing this (adding ".toFixed(2)" to their val()s):
var amount1 = $('[id$=boxAmount1]').val() != '' ? parseFloat($('[id$=boxAmount1]').val().toFixed(2)) : 0;
var amount2 = $('[id$=boxAmount2]').val() != '' ? parseFloat($('[id$=boxAmount2]').val().toFixed(2)) : 0;
. . .
It didn't; it fact, it broke the existing functionality.
So I then "dialed it back a bit" and tried on just the first "Amount" box like so:
$('[id$=boxAmount1]').val() == parseFloat($('[id$=boxAmount1]').val().toFixed(2));
...but that also failed (entering "10.5" and exiting/blurring did not convert the "10.5" to "10.50" as I hoped).
How can I cause the inputs to always expand or contract to display two digits? IOW:
"10" should become "10.00"
"10.5" should become "10.50"
"10.567" should become "10.57"
etc.