17 Replies Latest reply on Aug 1, 2008 3:33 PM by gkaiseril

    GetField and String

    Level 1
      I need help with my script. I am taking the value in A, B and C and end result is in D (i.e, 2, C, 8 end result in box is 2C8. Thank you for any help you can give me. I am using AdobeAcrobat v8 Professional.
      box1 = this.getField("Box1").value
      box2 = this.getField("Box2").value
      box3 = this.getField("Box3").value
      this.getField("Box1Box2Box3").value = str(box1) + str(box2) + str(box3)
        • 1. Re: GetField and String
          Bernd Alheit Adobe Community Professional & MVP
          Where did you define the function 'str'? That isn't a pre-defined JavaScript function.
          • 2. Re: GetField and String
            Patrick Leckey Level 3
            Also, why don't you use valueAsString instead of value?

            box1 = this.getField("Box1").valueAsString
            etc...
            • 3. Re: GetField and String
              gkaiseril MVP & Adobe Community Professional
              You can also use the ".toString()" method

              box1 = this.getField("Box1").value.toSrting();
              box2 = this.getField("Box2").value..toSrting();
              box3 = this.getField("Box3").value..toSrting();
              this.getField("Box1Box2Box3").value = box1 + box2 + box3

              You could even use the "fillin()" funciton provided in Acrobat's sample forms for the PFN

              On the distribution disk of the full, not upgrade", professional version 6 and above or the standard version below 6, contains some forms examples. One of the examples, "PFNFORM.PDF", contains the code for a document level function to concatenate up to 3 alpha strings and an optional separator:

              // Concatenate 3 strings with separators where needed
              function fillin(s1, s2, s3, sep) {

              /*
              Purpose: concatenate up to 3 strings with an optional separator

              inputs:
              s1: required input string text or empty string
              s2: required input string text or empty string
              s3: required input string text or empty string
              sep: optional seperator stirng

              returns:
              sResult concatinated string
              */

              // variable to determine how to concatenate the strings
              var test = 0; // all strings null
              var sResult; // reslut string to return

              // force any number string to a character string for input variables
              s1 = s1.toString();
              s2 = s2.toString();
              s3 = s3.toString();

              /*
              assign a binary value for each string present
              and adds this value to compute a value used to
              determine which action to be taken.

              The value is computed using a binary reprenstation for present(1) and not present(0).
              */
              if (s1 != "") test += 1; // string 1 present add binary value: 001
              if (s2 != "") test += 2; // string 2 present add binary value: 010
              if (s3 != "") test += 4; // string 3 present add binary value: 100

              /* return appropriate string combination based on
              calculated test value as a binary string
              */
              switch (test.toString(2)) {

              case "0": // no non-empty strings passed - binary 0
              sResult = "";
              break;

              case "1": // only string 1 present - binary 1
              sResult = s1;
              break;

              case "10": // only string 2 present - binary 10
              sResult = s2;
              break;

              case "11": // string 1 and 2 present - binary 1 + 10
              sResult = s1 + sep + s2;
              break;

              case "100": // only string 3 present - binary 100
              sResult = s3;
              break;

              case "101": // string 1 and 3 - binary 1 + 100
              sResult = s1 + sep + s3;
              break;

              case "110": // string 2 and 3 - binary 10 + 100
              sResult = s2 + sep + s3;
              break;

              case "111": // all 3 strings - binary 1 + 010 + 100
              sResult = s1 + sep + s2 + sep + s3;
              break;

              default: // any missed combinations
              sResult = "";
              break;
              }

              return sResult;
              }

              The above script will take into account any passed null string and adjust the returned string accordingly.

              To use, call, the function use the following 'Custom Calculation Script":

              box1 = this.getField("Box1").value;
              box2 = this.getField("Box2").value;
              box3 = this.getField("Box3").value;

              event.value = fillin(box1, box2, box3); // combine 3 strings

              To access another PDF file with version 5 or above, one needs to set the "disclosed"
              • 4. Re: GetField and String
                Level 1
                Geo Kaiser
                I created a field using the Text Field tool called Box 1, another field Box 2 and another Box 3. In field 4 (called Box1Box1Box3) I added the Java Script below but I do not get any result in Box 4. I must be missing something. Thank you for your help.
                ".toString()" method

                box1 = this.getField("Box1").value.toSrting();
                box2 = this.getField("Box2").value..toSrting();
                box3 = this.getField("Box3").value..toSrting();
                this.getField("Box1Box2Box3").value = box1 + box2 + box3
                • 5. Re: GetField and String
                  gkaiseril MVP & Adobe Community Professional
                  You need to use "." not ".." for stringing methods or properties together.

                  box1 = this.getField("Box1").value.toSrting();
                  box2 = this.getField("Box2").value.toSrting();
                  box3 = this.getField("Box3").value.toSrting();
                  this.getField("Box1Box2Box3").value = box1 + box2 + box3
                  • 6. Re: GetField and String
                    Level 1
                    I copied your script and placed it in Box1Box2Box3 but I still do not get any results. Thanks for having patience with me.
                    • 7. Re: GetField and String
                      Larry G. Schneider Adobe Community Professional & MVP
                      You might try spelling String right.
                      • 8. Re: GetField and String
                        Level 1
                        I tried that too.
                        • 9. Re: GetField and String
                          Bernd Alheit Adobe Community Professional & MVP
                          Where did you put the code? Get you any error message in the console?
                          • 10. Re: GetField and String
                            gkaiseril MVP & Adobe Community Professional
                            For the field calculaiton one should use the "event.value" and not hte field name.
                            • 11. Re: GetField and String
                              Level 1
                              box1 = this.getField("Box1").value.toString();
                              box2 = this.getField("Box2").value.toString();
                              box3 = this.getField("Box3").value.toString();
                              this.getField("Box1Box2Box3").value = str(box1) + str(box2) + str(box3)

                              I need help with this script. I am taking the value in A, B and C and end result is in D (i.e, 2, C, 8 end result in box is 2C8.

                              Would appreciate any help you can give me.
                              • 12. Re: GetField and String
                                Bernd Alheit Adobe Community Professional & MVP
                                Why do you use str() ? That is a undefined function.
                                • 13. Re: GetField and String
                                  Level 1
                                  I am working with a similar document.. where would this string of Box1, Box2,..etc go? Under the click event for my first box?
                                  • 14. Re: GetField and String
                                    George_Johnson MVP & Adobe Community Professional
                                    > I am working with a similar document..

                                    You need to provide more details about how you've set things up and what you want to happen.

                                    A common thing to do is set up the field that displays the result as a calculated field, meaning the code that sets its value is placed in the calculated field's Calculate event (custom calculation script). I would suggest the following:

                                    // Set this field value by concatenating the value of other fields
                                    event.value = getField("t1").valueAsString + getField("t2).valueAsString;

                                    where "t1" and "t2" are the names of text fields. Calculated fields should be set to read-only so the user does not attempt to enter data in them. Also, once the form is done make sure the field calculation order makes sense.

                                    George
                                    • 15. Re: GetField and String
                                      Level 1
                                      Ok here is my main goal... I'm creating a form where user's request the computer software they need for thier position. The pdf has a big list! So i would like the objects they check to populate to an area only seen when printing...
                                      How do i make it so when a user checks/selects 'CheckBox1' the word "WinXP" will appear in a text box below.
                                      If a user checks the next box 'CheckBox2' the phrase "MS Word" appears in a text box below and so on for about 20 check boxes, I could send my incomplete pdf. Thanks for any help or info.
                                      • 16. Re: GetField and String
                                        George_Johnson MVP & Adobe Community Professional
                                        See the other thread you started and respond to the questions I asked there.

                                        George
                                        • 17. Re: GetField and String
                                          gkaiseril MVP & Adobe Community Professional
                                          In AcorForms, you can set the text field's property "Form Field is:" to "Hidden but pritable" on the "Apperance" tab. You can add a "Custom calculation scirpt" on the "Calculation" tab to set the text field equal to the value of the check box's export value when the value of the check box is not "Off".