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

Question

Question

Forms - Purchase Order Example

asked on March 18, 2015

I developed a form in 9.1.1 with a table containing repeatable rows containing a 'quantity', 'price' and 'subtotal' column.  I also included a separate 'total' field.  Fields have been set up with the respective names 'quantity', 'price', 'subtotal' and 'total'.   Fields are also not read only.

I copied the Purchase Order Example into the form minus tax and shipping.  The form will accept entries for 'quantity' and 'price' but will not calculate 'subtotal' and 'total'.  Does anyone know why? Below is what I entered.      Thank you

  1. $(document).ready(function () {
  2.     $('.cf-table-block').on('blur', 'input', sumtotal);
  3.     $('.tax').on('blur', 'input', sumtotal);
  4.     $('.shipping').on('blur', 'input', sumtotal);
  5.     function sumtotal() {
  6.         var sum = 0;
  7.         $('.cf-table-block tbody tr').each(function () {
  8.             var s = 0;
  9.             s = parseNumber($(this).find('.price input').val()) * parseNumber($(this).find('.quantity input').val());
  10.             $(this).find('.subtotal input').val(s);
  11.             sum += s;
  12.             sum += parseNumber($('.tax input').val()) + parseNumber($('.shipping input').val());
  13.         });
  14.         $('.total input').val(sum);
  15.    }
  16.     function parseNumber(n) {
  17.         var f = parseFloat(n); //Convert to float number.
  18.         return isNaN(f) ? 0 : f; //treat invalid input as 0;
  19.     }
  20. });
0 0

Replies

replied on March 18, 2015

Ken, Thank you. I tried the following and it seems to be working well.  thx sd

$(document).ready(function() {
     $('.cf-table-block').on('blur','input',sumtotal);
     function sumtotal() {
       var quantity = 0;
       var price = 0;
       var total = 0;
       var subtotal =0;
      
       $('.cf-table-block tbody tr').each(function (){
         quantity = parseNumber($(this).find('.quantity input').val())
         price = parseNumber ($(this).find('.price input').val());
         subtotal = (quantity * price);
        
         $(this).find('.subtotal input').val(subtotal);
         total += subtotal;      
    });
    $('.total input').val((total).toFixed(2));
  }
  function parseNumber(n) {
    var f = parseFloat(n); //Convert to float number.
    return isNaN(f) ? 0 : f; //treat invalid input as 0:
  }
});

1 0
replied on March 18, 2015

the subtotal and total fields are also currency fields? 

 

I would try separating out some of that so that your calculations are using parenthesis to group things and also not referencing another function. 

 

Also, why not store the tax and shipping into variables once before doing it for each line? 

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

Sign in to reply to this post.