9 Replies Latest reply on Dec 16, 2010 6:26 AM by Dolfan24

    Making a value appear

    Dolfan24

      Hello,

      I'm new to scripting in Acrobat.  I've been doing it a total of about 45 minutes.  I need a little help.

       

      I'm creating a survey with multiple choice radio buttons.  The answers to these buttons generate a point value.  The total point value of all the questions is displayed as a sum.  Easy enough.

       

      I also have a page with what looks like a table (but isn't, its rows and columns of fields).  I have four columns and 28 rows.

      Each column represents a series of questions as mentioned above.  The rows represent the possible total score of those questions.

       

      Example - There are seven questions.  The possible answers will generate a value of 0 to 4.  The sum of all the answers then can be from 0 - 28.

       

      The "table" has the 28 rows, labeled 28 at the top down to zero at the bottom, representing each possible score.

       

      What I need to do is have the total score for that series of questions appear as the score in the appropriate field.  So if the total score is 16, then I need the number 16 to appear in the 16th row, and nothing else appear in the other 27 rows.

       

      So with absolutely no knowledge of scripting, my best guess at this would be,

      if (fieldname16 = 16)

      then print 16

      else null

       

      Was I even close? LOL

       

      I'm assuming it's a very simple script. I've tried searching bing/google.. I've watched a few videos on Lynda.com... I've looked at various Adobe resources but to no avail.  I'm hoping someone can help me relatively easily.

       

      Thanks in advance

        • 1. Re: Making a value appear
          gkaiseril MVP & Adobe Community Professional

          Have you looked at the MDN JavaScript Reference and the Acrobat JS API Reference?

           

          JavaScript is object orientated, so one needs to establish a link to the object and then access a property or method for that object.

           

          Do you know how to create exclusionary groups of radio buttons or check boxes?

          Have you been able to total the results of your questions?

          Is that total in a field or variable?

           

          'this' refers to the open and focused PDF document. You can access a field on the current focused PDF with the 'getField(sFieldName)' method. Fields have a 'value' propterty. So putting it all together one uses 'this.getFeild('16').value' to get the value of a field named '16'.

           

          Asumming your queston check boxes or radiou button for each question is of the format 'Q#' where "#' is the number of the question, then you could compute the sum with a script like in a mouse up action for a button:

           

          // define a variable for the sum ot the questions:

          var sum = 0;

          // variable for the value of a given question

          var score = 0;

          // loop through the questions 1 -28

          for(i = 1, i < 29, i++) {

             // get the i question

            score = this.getField("Q" + i).value

            // sum score if a box is chekced

            if (score != "Off") sum += Number(score);

          } // end loop

          // clear the results field

          this.resetForm(["0", "1", "3",... ,"28");

          // put the value into the appropriate row

          this.getField(sum).value =  sum; 

           

          I have found Acrobat Users Community has very good free training resources.

          1 person found this helpful
          • 2. Re: Making a value appear
            Dolfan24 Level 1

            Thank you so much for responding.

             

            Have you looked at the MDN JavaScript Reference and the Acrobat JS API Reference?

            --> No, I've never had any luck with Javascript (or any programming for that matter).  I will look through these references and see if anything makes sense.

             

            Do you know how to create exclusionary groups of radio buttons or check boxes?

            Have you been able to total the results of your questions?

            Is that total in a field or variable?

            --> Yes, each question has five radio buttons, all of the same field name, and the selection for each question is summed up in a total field. I can get the sum to show up anywhere. I simply need the content of the total field to appear in a specific field based on the sum of questions. If the total of the seven questions under chapter one is 15, then I need it to appear in the field named field15 under the chapter one column, for instance, but the remaining columns need to be blank.

             

            The end result will have four columns of 28 fields but only one field in each column will have the sum results, to give sort of a graph appearance. I can do this in Numbers or Excel, but we want to use the original published PDF document, and making it an interactive document is the perfect solution

             

            I cannot include the document I'm working on as it's copyrighted and I'm not permitted to release it to anyone.  I can create a document similar to what I am trying to achieve if that would help, although based on the script you provided below it appears you know what I'm trying to accomplish and it looks like it will work, looking at it logically.  But not being able to read it properly, I can't know.

             

             

            I have a mental block when it comes to programming and scripting.  I can code html in my sleep. I can use any number of software packages, from InDesign, Photoshop, Corel Draw, Word, Numbers, Pages, Premiere you name it, I can use it. I work on both MAC and PC.  I'm rather intelligent when it comes to programs like that. But when I get to doing anything with scripting, like ActionScript in Flash.. I'm the class dunce, a drop-out, IQ goes from 150 to 0 in a second. It's the one thing I simply can't ( and I never use the word can't) learn. I've tried several times taking programming classes and I've failed out of each one, including Basic!  I have a premium subscription to lynda.com and that didn't help!  I'm beyond frustrated with myself. If I could get over that one last mental hurdle, I would be an ace with it, I know it! 

             

            Thanks again

            • 3. Re: Making a value appear
              George_Johnson MVP & Adobe Community Professional

              > I can create a document similar to wha...

               

              I think that would be a good idea. I've read your description a number of times and don't understand how the form is set up, so a sample would help a lot.

              • 4. Re: Making a value appear
                Dolfan24 Level 1

                Open the form and select one answer from the four questions (the actual form has four sets of seven questions).

                The selections are totaled on the bottom. 

                 

                This number on the bottom needs to also appear in the box on the right next to the corresponding number.

                So if your selections total 9, and 9 appears in the total on the bottom, I also want 9 to appear in the box next to 9 leaving the other boxes blank.  If you change an answer and the total changes to 11, the 9 goes away and 11 appears in the 11 box.

                 

                I hope this clarifies.

                 

                Thanks George,

                 

                (my name's George also)

                 

                https://files.me.com/dolfan24/badxle

                • 5. Re: Making a value appear
                  gkaiseril MVP & Adobe Community Professional

                  You will have to cleanup your field names for answer 4 and 20.

                   

                  The custom calculation script for the Total Score field:

                   

                  // define a variable for the sum ot the questions:
                  var sum = 0;
                  // variable for the value of a given question
                  var score = 0;
                  // loop through the questions 1 -28
                  for(i = 1; i < 5; i++) {
                     // get the i question
                    score = this.getField("Input-Answer" + i).value
                    // sum score if a box is chekced
                    if (score != "Off") sum += Number(score);
                  } // end loop
                  event.value = sum;
                  // clear the results field
                  var aFields = new Array("Answer0", "Answer1",
                  "Answer2", "Answer3", "Answer4", "Answer5",
                  "Answer6", 'Answer7','Answer8','Answer9',
                  'Answer10', 'Answer11', 'Answer12', 'Answer13',
                  'Answer14', 'Answer15', 'Answer16', 'Answer17',
                  'Answer18', 'Answer19', 'Answer20');
                  this.resetForm(aFields);
                  if (sum != 0) {
                  // put the value into the appropriate row
                  this.getField('Answer' + sum).value =  sum; 
                  }

                  • 6. Re: Making a value appear
                    George_Johnson MVP & Adobe Community Professional
                    (my name's George also)

                     

                    Guess what GKaiseril's name is...

                    1 person found this helpful
                    • 7. Re: Making a value appear
                      Dolfan24 Level 1

                      So this post is restricted to brilliant men?

                       

                       

                      • 8. Re: Making a value appear
                        Dolfan24 Level 1

                        I will give this a shot.  Wish me luck.

                         

                        Any advice on how to get over my mental block on learning scripting and programming?

                         

                        I don't know what the problem is.  I may have taken my mental blocks out to play with them at a younger age and never put them back in correctly.

                        • 9. Re: Making a value appear
                          Dolfan24 Level 1

                          BEAUTIFUL!!!!

                           

                          With a few minor modifications to some logical issues (changing field names to match the actual document, changing "for(i = 1; i < 5; i++) {" to "for(i = 1; i < 8; i++) {" because I actually have seven questions, not four) it was dead on!  Thank you.  The notes helped me modify it perfectly, otherwise it would still be Greek to me. I have no idea what any of it says or means, but it works.

                           

                          I hope that some day I'll be able to identify what it is about programming or scripting that keeps me from learning how to do it.  Because once I do, you'll have another "George" on here helping others.  We could be the Three AmiGeos!

                           

                          Thanks again to both of you.

                           

                          George