2 Replies Latest reply on Mar 1, 2017 5:50 AM by robd64027506

    Add numbers in Javascript

    robd64027506

      I have a series of numbers that I need to add, they are in 9 fields. The page is a template, the first problem was getting it change the names of the fields to match the spawned page within the script. I solved that problem.

       

      The current problem is that if one of the fields is blank, it does not read that field as a '0', it stops adding and combines the rest of the numbers as if they were text.

      So, if the first 3 fields were 1,1,2 the result would be '4', however if they were 1,1, (blank),2 I would get '22'. It adds the first 2 numbers, then it hits the blank, then it will combine the numbers thereafter.  1,1,(blank),2,3,4 would be 2234, I want it to = 11

       

      I need it to consider a blank field a zero so that it continues to add, the 'custom calculation  script' is below, please help.

       

      (function () {var f_name = event.target.name; var aName = f_name.split("."); var f_prefix = aName[0] + "." + aName[1];

      event.value =

      this.getField([f_prefix] + ".ADA A QTY").value

      +

      this.getField([f_prefix] + ".ADA B QTY").value

      +

      this.getField([f_prefix] + ".ADA C QTY").value

      +

      this.getField([f_prefix] + ".ADA D QTY").value

      +

      this.getField([f_prefix] + ".ADA E QTY").value

      +

      this.getField([f_prefix] + ".ADA F QTY").value

      +

      this.getField([f_prefix] + ".ADA G QTY").value

      +

      this.getField([f_prefix] + ".ADA H QTY").value

      +

      this.getField([f_prefix] + ".ADA I QTY").value

      })();