kpcollier Posted December 18, 2019 Report Share Posted December 18, 2019 If someone could help me with a couple of things: 1). When the page first loads, all of the Total fields start with NaN. Is there a way I can start them out as blank, or 0? I tried putting in a placeholder, but it still doesnt work. 2.) I cannot seem to figure out how to get the currency format to work on these Total fields. The SubTotal ends with 1 digit after the decimal point, and the County Tax Total often has many digits after the decimal. Is there a way I can format all of these Total fields as currency? They are already set as Currency DataType and I have the app localization set for currency as well, to no effect Thanks again. //Virtual 13 is the new subtotal after calculations document.addEventListener('DataPageReady', function (event) { function calculate() { var subTotal = parseFloat(document.getElementById("InsertRecordSubtotal").value); var markUp = parseFloat(document.getElementById("InsertRecordMarkUp").value); var countyTax = parseFloat(document.getElementById("InsertRecordCounty_Tax").value); var miscPerc = parseFloat(document.getElementById("InsertRecordMisc_Percent").value); var freight = parseFloat(document.getElementById("InsertRecordFreight_Total").value); var markUpTotal = document.getElementById("InsertRecordMarkUp_Total").value = (subTotal) * (markUp); var countyTaxTotal = document.getElementById("InsertRecordCountyTax_Total").value = (subTotal) * (countyTax); var miscPercTotal = document.getElementById("InsertRecordMisc_Percent_Total").value = (subTotal) * (miscPerc); document.getElementById("cbParamVirtual13").value = (subTotal) + (markUpTotal) + (countyTaxTotal) + (miscPercTotal) + (freight); } setInterval(calculate, 1500); }); Quote Link to comment Share on other sites More sharing options...
kpcollier Posted December 19, 2019 Author Report Share Posted December 19, 2019 Also, I have read that parseFloat is not good practice for calculations. However, when I try parseInt or anything else, it just adds up the fields like strings. So 2000 + 1234 would be 20001234 instead of 3234. Quote Link to comment Share on other sites More sharing options...
kpcollier Posted December 27, 2019 Author Report Share Posted December 27, 2019 Any help with this? Quote Link to comment Share on other sites More sharing options...
Vitalikssssss Posted December 30, 2019 Report Share Posted December 30, 2019 On 12/28/2019 at 1:10 AM, kpcollier said: Any help with this? Hi @kpcollier, Why do not you use Calculated value to perform such calculation? You can use isNull function in Calculated value in order to replace null with zero. IsNull([@field:Number], -0) Hope this helps. Regards, vitalikssssss Quote Link to comment Share on other sites More sharing options...
Vitalikssssss Posted December 30, 2019 Report Share Posted December 30, 2019 @kpcollier, You can use the following JS code if you decide to use a custom code. <script type="text/javascript"> function calculate() { var subTotal = isNaN(parseFloat(document.getElementById("InsertRecordSubtotal").value)) ? 0 : parseFloat(document.getElementById("InsertRecordSubtotal").value); var markUp = isNaN(parseFloat(document.getElementById("InsertRecordMarkUp").value)) ? 0 : parseFloat(document.getElementById("InsertRecordMarkUp").value) ; var countyTax = isNaN(parseFloat(document.getElementById("InsertRecordCounty_Tax").value)) ? 0 : parseFloat(document.getElementById("InsertRecordCounty_Tax").value); var miscPerc = isNaN(parseFloat(document.getElementById("InsertRecordMisc_Percent").value)) ? 0 : parseFloat(document.getElementById("InsertRecordMisc_Percent").value); var freight = isNaN(parseFloat(document.getElementById("InsertRecordFreight_Total").value)) ? 0 : parseFloat(document.getElementById("InsertRecordFreight_Total").value); var markUpTotal = document.getElementById("InsertRecordMarkUp_Total").value = (subTotal) * (markUp); var countyTaxTotal = document.getElementById("InsertRecordCountyTax_Total").value = (subTotal) * (countyTax); var miscPercTotal = document.getElementById("InsertRecordMisc_Percent_Total").value = (subTotal) * (miscPerc); document.getElementById("cbParamVirtual1").value = (subTotal) + (markUpTotal) + (countyTaxTotal) + (miscPercTotal) + (freight); } setInterval(calculate, 1500); </script> Regards, vitalikssssss kpcollier 1 Quote Link to comment Share on other sites More sharing options...
kpcollier Posted December 30, 2019 Author Report Share Posted December 30, 2019 2 hours ago, Vitalikssssss said: Hi @kpcollier, Why do not you use Calculated value to perform such calculation? You can use isNull function in Calculated value in order to replace null with zero. IsNull([@field:Number], -0) Hope this helps. Regards, vitalikssssss I was originally using calculated fields for this page, but because I have so many of them, it made the loading speed incredibly slow. This is used for estimating so I need a ton of dropdowns and calculations on a single form. Thank you for the updated code - I greatly appreciate it! Quote Link to comment Share on other sites More sharing options...
kpcollier Posted January 7, 2020 Author Report Share Posted January 7, 2020 If anyone could help me out with trying to format this, it would be great! ALL of my JS calculations are coming out as just a number. (i.e. '12345.678' instead of '12,345.68'). I think it is because I am manipulating the numbers through the js script above, so it is just ignoring the formatting options. I am not sure. All of the Totals fields are currency datatype, but they still show up as just a number. If there is anyway I can format it as USD currency, that would be great. TIA Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.