3 Replies Latest reply on Apr 3, 2009 1:39 PM by (Michael_Frommer)

    Totals not recalculating when dependant data changes

      You can find my form (click on REGISTRATION FORM) at http://www.sifmadiv.org/en/cev/30. Looking at it might help you understand what I am about to explain.

      I am currently using the basic (built in) Sum or Product calculations for all of the different Total fields (as explained below). The problem exists that when a change of selection is made on the radio and check boxes (which controls data for the downstream calculations) after those initial selections and calculations, the Totals fields are not recalculating when some of the dependant data changes. (More details on that explained later.)

      I have tried to correct the order of the calculations, but I can't seem to get it to stay in the order I set. The other idead I have gotten from my search of this forum, is to create a document level script and call to that script from the first group of Total fields. I am totally new at scripting (just started reading a couple of days ago) and would appreciate your assistance for document level scripts.

      I think the idea of a document level script would solve my problem, but perhaps it should be called to from another point (the radio boxes, upon selection?, both?)

      Let me describe the fields and their actions - backwards; starting with the very last of the Total fields, so you see all dependencies:

      a total field ("TotalAmountDue") which is dependant on

      other total fields (the sum of "CostMemberWorkshop" + "CostNonMemberWorkshop" + "CostMemberDinner" + "CostNonMemberDinner"),

      each which is the respective product of a total field ("NumberMemberWorkshop", "NumberNonMemberWorkshop", "NumberMemberDinner", "NumberNonMemberDinner"), each being auto calculated

      based on respective hidden fields ("MW1" + "MW2" + "MW3" + "MW4") ("NMW1" + "NMW2" + "NMW3" + "NMW4") ("MD1" + "MD2" + "MD3" + MD4") ("NMD1" + "NMD2" + "NMD3" + "NMD4"),

      (The hidden fields are populated based on the export value of radio/check boxes which contain an 'if ...else' statement)

      and a set respective price field ("PriceMemberWorkshop", "PriceNonMemberWorkshop", "PriceMemberDinner", "PriceNonMemberDinner")

      If someone changes their selection of the radio/checkboxes, the hidden fields (which are populated based on the 'if ...else' staement are automatically and correctly updated, but the downstream totals are not.
        • 1. Re: Totals not recalculating when dependant data changes
          Level 1
          CORRECTION:
          It was suggested that the document level script be called to from the hidden quantity fields (see original post).
          • 2. Re: Totals not recalculating when dependant data changes
            MarkWalsh Level 4
            Where are you putting the call to the calculate function?

            If you put it into the On Blur event for the entry fields, for example, it should work.
            • 3. Re: Totals not recalculating when dependant data changes
              Level 1
              On blur wont work in this case because the fields that need to show the totals are not input by the user.

              I did finally get all total & sub-cost fields to properly update calling two document level scripts from the attendee type/event total field, which is auto populated when the user selects radio and check boxes to identify if they are a member or not and which of two events they ware registering for. Those radio/check boxes first populate hidden fields with '1' or '0', and those hidden fields must then be totaled by the script.

              For example, in the NumberMember Workshop (read only) field I call these two custom scripts:
              ]calcTotalAttendees();
              calcTotalCost();

              function calcTotalAttendees()
              {
              // Call this function each time AttendeeType is selected.
              // Calculate the sum of Members attending the Dinner.
              this.getField("NumberMembersDinner").value = ((this.getField("MD1").value) + (this.getField("MD2").value) + (this.getField("MD3").value) + (this.getField("MD4").value));
              // Calculate the sum of Non-Members attending the Dinner.
              this.getField("NumberNonMembersDinner").value = ((this.getField("NMD1").value) + (this.getField("NMD2").value) + (this.getField("NMD3").value) + (this.getField("NMD4").value));
              // Calculate the sum of Members attending the Workshop.
              this.getField("NumberMembersWorkshop").value = ((this.getField("MW1").value) + (this.getField("MW2").value) + (this.getField("MW3").value) + (this.getField("MW4").value));
              // Calculate the sum of Non-Members attending the Workshop.
              this.getField("NumberNonMembersWorkshop").value = ((this.getField("NMW1").value) + (this.getField("NMW2").value) + (this.getField("NMW3").value) + (this.getField("NMW4").value));
              }

              function calcTotalCost()
              {
              // Call this function each time the number of attendees per event gets updated.
              // Calculate the cost of Members attending the Dinner.
              this.getField("CostMemberDinner").value = ((this.getField("NumberMembersDinner").value) * (this.getField("PriceMemberDinner").value));
              // Calculate the cost of Non-Members attending the Dinner.
              this.getField("CostNonMemberDinner").value = ((this.getField("NumberNonMembersDinner").value) * (this.getField("PriceNonMemberDinner").value));
              // Calculate the cost of Members attending the Workshop.
              this.getField("CostMemberWorkshop").value = ((this.getField("NumberMembersWorkshop").value) * (this.getField("PriceMemberWorkshop").value));
              // Calculate the cost of Non-Members attending the Workshop.
              this.getField("CostNonMemberWorkshop").value = ((this.getField("NumberNonMembersWorkshop").value) * (this.getField("PriceNonMemberWorkshop").value));
              // Calculate the TotalAmountDue.
              this.getField("TotalAmountDue").value = ((this.getField("CostMemberDinner").value) + (this.getField("CostNonMemberDinner").value) + (this.getField("CostMemberWorkshop").value) + (this.getField("CostNonMemberWorkshop").value));
              }