5 Replies Latest reply on Dec 18, 2013 2:07 PM by lapneto

    Calculations after spawning a page

    lapneto Level 1

      Hello everyone,


      This forum has been so helpful that I felt like asking another question.

      I have successfully added a button to my form to add another page based on a hidden template.

      Everything seems fine, except for the fact that I can in no way get the calculations to work automatically.

      I took a look around the forum, but since I am no programmer and am doing this out of curiosity, could any of you point me in the right direction?

      I know the field names are automatically renamed when spawning and this is necessary, but I can not find a way of successfully referencing to the newly created fields.

      Just for ease of reference, the fields in the template are named "Mod_A_P_A_1", "Mod_A_P_A_2", "Mod_A_P_A_3" etc, so the spawned page will look like "P#.Mod_A_P_A_1" etc...

      Thanks in advance for all the help!

        • 1. Re: Calculations after spawning a page
          try67 MVP & Adobe Community Professional

          Combining calculations with spawning pages is quite a complex task. You basically need to write a script that looks up the fields to use in the calculation, because you can't know in advance what their names are going to be.

          • 2. Re: Calculations after spawning a page
            George_Johnson MVP & Adobe Community Professional

            So what is the calculation that you'd like to perform? The field name of a calculated field will have the same prefix (e.g, P2.Mod_A_P_A_1) as the other fields on the page and can be retrieved in the script using the event.target.name property. For example:


            // Split this field's name at the periods

            var fna = event.target.name.split(".");


            // Get the field name prefix of all fields on the page

            var fp = fna.length > 1 ? fna[0] + "." + fna[1] + "." : "";


            // Perform a simple calculation

            event.value = getField(fp + "text1").value - getField(fp + "text2").value;

            • 3. Re: Calculations after spawning a page
              lapneto Level 1

              Thank you both for responding, your help as usual is greatly appreciated.

              @George: the calculation is really simple, just a sum of these specific fields... I tried to run your script and... it works!

              Guess I say that code somewhere else in the forum when searching, but as I dont understand all the syntax, I could not get it to work...

              Thank you so much for all the help guys!

              • 4. Re: Calculations after spawning a page
                gkaiseril MVP & Adobe Community Professional

                When a new page is spawned form a template and the fields are renamed, the field names from the template are changed to include a prefix of the page number and the template name. It is up to the developer to have the code adjsut for these changes either in the form fields or in the document level functions.

                • 5. Re: Calculations after spawning a page
                  lapneto Level 1

                  Thanks a lot for the help, guys! I was able to get it to work after your kind guidance!

                  1 person found this helpful