9 Replies Latest reply on Nov 26, 2012 3:05 AM by try67

    AFsimple_calculate problem


      Im making a very (probably even too) dynamic order form in acrobat.


      In this form, you basicly select a product and some extra features and then you will see the total price of that product. I've added a button which, once clicked, will show a new line where you can select another product and features. So basicly my form consists of small subforms, each containing inputs for a product. To easily hide/show each product, Im using parent-child notation for the subforms: so the first product fields are named 1.productname,1.productprice etc., second product fields are named 2.productname etc. etc.


      to show the price of the product, each subform has a textfield called x.Totaal which I created like this:


      var arr = new Array('+id+".Abonnement"',id+".sms",id+".international",id+".Data");


      f = this.addField(id+".Totaal","text",this.pageNum,rct5);

      f.textSize = 8;

      f.readonly = true;

      f.alignment = "right";



      id is set above this code and is working fine, it increases which each new subform created.


      so basicly this field should show the sum of the 4 fieldvalues that are stored in arr.

      but the javascript console shows this error:

      arr is not defined


      ReferenceError: arr is not defined



      if I change the notation to this: f.setAction("Calculate",'AFSimple_Calculate("SUM",'+arr+')');

      I get the error:

      SyntaxError: missing ) after argument list



      and finally this notation: f.setAction("Calculate",'AFSimple_Calculate("SUM",new Array(id+".Abonnement",id+".sms",id+".international",id+".Data"))');

      gives me no error but when I check the properties of the textfield, it calculates the sum of the fields .Abonnement,.sms,.Data,.international without the id in front of it.


      I'm thinking it's a matter of the right notation and combination of " and '. I like the AFSimple_Calculation method, because it automaticly updates once on the 4 values is changed...

      Any help is greatly appreciated...


      Or if there is another way to automaticly update the textfield when one of the 4 changes, that okay too ofcourse



      extra info, don't know if it's relevant:

      the button launches a function, which I created in the document javascripts.

        • 1. Re: AFsimple_calculate problem
          try67 MVP & Adobe Community Professional

          The second parameter of AFSimple_Calculate needs to be a comma-separated

          string containing the names of the fields you want to sum up.

          The variable arr that you define in your code is not available in the

          context of the action that you're setting, and anyway it's not the right

          variable type. You should use a string, not at array of strings.


          Also, I would avoid mixing single and double-quotes. It's a bit confusing.

          Instead, use just double-quotes, but escape them when they are in a string.

          • 2. Re: AFsimple_calculate problem
            Test Screen Name Most Valuable Participant

            A tip. Getting to grips with escaped strings can be tough, for example knowing that to get The "best" stuff in a string you have to write "The \"best\" stuff" and to get "The \"best\" stuff" in a string you have to write "\"The \\\"best\\\" stuff\"" .


            To confirm your string contains what you think it does, simply display it in a message or the console.

            • 3. Re: AFsimple_calculate problem
              Panna_man Level 1

              thx for the info. I got the use of an array from this: http://www.verydoc.com/documents/acrojsguide/pg_0101.htm

              The single quote around AFsimple_calculate seem to be mandatory though, can't replace them with ".


              any idea how to succesfully create the string? it works great for a hardcoded string like 'AFsimple_calculate("SUM","3.sms,3.Data")' for example. But as soon as I add a variable it doesn't work...


              Also when I check the console for errors and I select "Script and Console", the displayed script doesn't contain any adjustments. So I'm not even sure the script is succesfully reloaded or that the errors that are displayed apply to the current script.....

              • 4. Re: AFsimple_calculate problem
                try67 MVP & Adobe Community Professional

                Try this:

                setAction("Calculate", "AFSimple_Calculate(\"SUM\",\"3.sms,3.Data\")")

                (make sure you use the correct spelling. JS is case-sensitive, so AFsimple_calculate is not going to work)

                • 5. Re: AFsimple_calculate problem
                  Panna_man Level 1

                  the problem isn't \". setAction("Calculate",'AFsimple_Calculate("SUM","3.sms,3.Data")'); is a correct syntax. What I want is to be able to insert a variable instead of the 3. So that for product 4, 4.Totaal will be created and that it will calculate the sum of 4.sms and 4.Data...


                  I tried creating a string first like:

                  arr = id+".sms,"+id+".Data";



                  but it just returns the "arr is not defined" error.


                  I'll create a test textfield and execute the code line by line in the console, see if the error is truely in the AFsimple_Calculate syntax...

                  • 6. Re: AFsimple_calculate problem
                    try67 MVP & Adobe Community Professional

                    setAction("Calculate", "AFSimple_Calculate(\"SUM\",\"" + id + ".sms," + id + ".Data\")")

                    • 7. Re: AFsimple_calculate problem
                      Panna_man Level 1

                      thx! that did the trick

                      • 8. Re: AFsimple_calculate problem
                        Panna_man Level 1

                        additional question:


                        the form is complete now, but when I try it on another computer with adobe reader, it doesn't work. Clicking a button which launches a javascript functions results in an error mentioning security...what is the right way for exporting the pdf to be able to run it on another computer using Reader?

                        • 9. Re: AFsimple_calculate problem
                          try67 MVP & Adobe Community Professional

                          The setAction method can't be used in Reader.