3 Replies Latest reply on Aug 31, 2017 1:37 AM by try67

    Trouble getting a field value for a calculation


      I am working on a form to do some simple calculations based on quantity and price of several fields.


      In the form, each product could have a single quantity or multiple quantities (if there are product variations such as color, size, etc).

      I have set up the field so that each product group has a unique name, with the various quantity boxes having a suffix.:

      Ball Price 001

      Ball Quantity 001-1

      Ball Quantity 001-2


      Ball Total 001


      The script then loops through all fields, finds the appropriate quantity fields based off the event field then should put them into a total quantity variable.

      However it is not functioning (returns undefined).


      Here is the code I have in the custom calculation:

      // On The Product Calculation Sections
      var s = event.target.name;
      var suffix = s.substring(s.length-3);
      var prefix = s.substring(0,5);
      var price = this.getField(prefix + "Price " + suffix).value;
      var quantity = 0;
      for (var i=0; i<this.numFields; i++) 
        var fname = this.getNthFieldName(i);
        var newName = fname.substring(0,fname.length-2);
        if(newName == prefix + "Quantity " + suffix)
          console.println(newName); //THIS WORKS AND SHOWS THE CORRECT FIELDS
          quantity.value += newName.value; //DOES NOT WORK
      event.value = quantity * price; //DOES NOT WORK



      And here is a link to the form as I have set it up currently (only 2 products but will have hundreds). This may be easier to see how it is set up

      Dropbox - Rugby Products.pdf


      Since there will be hundreds of fields to loop through each time a quantity is updated, perhaps there could be a better way to achieve what I am trying?