You are viewing limited content. For full access, please sign in.

Question

Question

LF forms JavaScript/table

asked on June 2, 2023 Show version history

I have a table set up to calculate the total.  seems like anything 3 digits calculates correctly except for when i enter the amount in thousands, it looks like the code drops the "0" and returns just the first digit. ie: $3000 shows an adjustment total of $3. 

$(document).ready(function() { 
  $(document).on('blur change', '.chg_amount input', sumtotal);
  
  function sumtotal() {
        var s = 0;
        $('.chg_amount input').each(function () {
            s += parseNumber($(this).val().replace('-', ''));
        });
        $('.total input').val(s.toFixed(2));
    }
    function parseNumber(n) {
        var f = parseFloat(n); //Convert to float number.
        return isNaN(f) ? 0 : f; //treat invalid input as 0;
    }
 

0 0

Answer

SELECTED ANSWER
replied on June 2, 2023

I have found that it is easier to use formulas for this type of table math than it is to use JavaScript.

I made a video demonstrating the strategy I am referring to: https://youtu.be/VZwdMPyr5mE

I originally found the technique here: Error in table when calculating Line Total - Laserfiche Answers.

I hope this helps.

1 0
replied on June 2, 2023

thanks John!  i comment out the  sumtotal function in j/s and used the advanced tab that you showed on your video to total up the amount.  thank you!

 

$(document).ready(function() { 
  $(document).on('blur change', '.chg_amount input', sumtotal);
  
  function sumtotal() {
        var s = 0;
  //      $('.chg_amount input').each(function () {
  //          s += parseNumber($(this).val().replace('-', ''));
  //      });
        $('.total input').val(s.toFixed(2));
    }
    function parseNumber(n) {
        var f = parseFloat(n); //Convert to float number.
        return isNaN(f) ? 0 : f; //treat invalid input as 0;
    }

0 0

Replies

You are not allowed to reply in this post.
You are not allowed to follow up in this post.

Sign in to reply to this post.