4 Replies Latest reply on Jan 6, 2009 1:30 PM by (Tim_Jeske)

    Custom Calculation Help

    Level 1
      I would like to calculate the total (sum) amount of buttons with a certain state. I have set up a bunch of buttons with this script:

      var buttonState = event.target.buttonGetCaption() == ""; event.target.buttonSetCaption(buttonState ? "O" : "");

      It basically changes the caption to an "O" which with the right font simulates a circle. On my form users "circle" their choices. I want to be able to give them a total of their choices.

      I know that I can get the state using this:

      var f = this.getField("My field 1"); f.buttonGetCaption();

      What I don't know is how to write the calc script to calculate the total number of buttons with the state/caption "O".
        • 1. Re: Custom Calculation Help
          Level 1
          If I use this basic set up:

          var f = this.getField("M1 Zone.0.0.0.0.0.0"); var Val1 = f.buttonGetCaption(); var g = this.getField("M1 Zone.0.0.0.0.0.1"); var Val2 = g.buttonGetCaption(); var ValTotal = event.value = (Val1 + Val2);

          Then I get for ValTotal the total number of "O" 's like this ... OO. Isn't there a way convert that into a number?

          Or can I use a conditional statement and assign an "O" to = 1? How do I do that?
          • 2. Re: Custom Calculation Help
            Level 1
            OK, I found out that this much works:

            var g = this.getField("M1 Zone.0.0.0.0.0.1"); var Val2 = (g.buttonGetCaption() == "O");
            var f = this.getField("M1 Zone.0.0.0.0.0.0"); var Val1 = (f.buttonGetCaption() == "O");
            event.value = (Val1 + Val2);

            It return the an integer. So I put that as a custom calculation script in a text field but the field doesn't auto calculate. I have to delete the value and the it recalculates. How would I get that to calculate after a button is pushed?
            • 3. Re: Custom Calculation Help
              gkaiseril MVP & Adobe Community Professional
              Why not check the value of the check boxes?

              var g = this.getField("M1 Zone.0.0.0.0.0.1");
              var Val2 = g.value;

              var f = this.getField("M1 Zone.0.0.0.0.0.0");
              var Val1 = f.value;

              // Debugging help
              console.show();
              console.clear();
              console.println("f " + f);
              console.println("Val1 " + Val1);
              console.println("g " + g);
              console.println("Val2 " + Val2);

              // end Debugging help

              // set values to 1 if not Off else zero
              if (Val1 != "Off") Val1 = 1;
              else Val1 = 0;
              if (Val2 != "Off") Val2 = 1;
              else Val2 = 0;

              console.println("Val1 " + Val1);
              console.println("Val2 " + Val2);

              event.value = Number(Val1) + Val2;

              You may also need to check and reset the calculation order for the form.
              • 4. Re: Custom Calculation Help
                I'm working on developing a PDF form in which I have several places where I need to calculate registration fees on the basis of the number of people being registered for an event. Thus, I have a field for the user to fill in the number of registrants at $75.00 each; a field for indicating the number of registrants at $90.00 each; and the number of registrants at the rate of $120.00 each. I want to calculate the total amount for each of those lines individually and get a grand total at the bottom.

                How do I calculate 7 (entered in field by user) x 75.00 and come up with a total?
                How do I calculate 3 (entered in field by user) x 90.00 and come up with a total etc.

                Thanks!

                T