4 Replies Latest reply on Aug 29, 2011 8:32 AM by gkaiseril

    new line

    jck_drmjn Level 1

      I have placed following code under address field.Each field - Text1, Text2, Text3, Text4 will start on new line.

       

       

      this.getField("Address").value= this.getField("Text1").value \n this.getField("Text2").value \n this.getField("Text3").value \n this.getField("Text4").value;

       

      It shows error. What is the perfect code for this purpose?

        • 1. Re: new line
          gkaiseril MVP & Adobe Community Professional

          The character string "\n" is a character string and not a variable name. Enter the character string with the correct delimiters for entering a character string..You will also need to use the concatenation operator.

           

          The sample forms in the PFN folder of the Acrobat distribution disk have a function for combining form fields and adjusting for missing or null data elements.

          • 2. Re: new line
            jck_drmjn Level 1

            Thanks for reply.

             

            Would you tell me how can I get correct delimiters for new line?

             

            Would you clarify me PFN folder?

             

            I'd be glad if you'd help me.

             

            Thanks

            • 3. Re: new line
              jck_drmjn Level 1

              Thanks.

               

              I have got answer.

              • 4. Re: new line
                gkaiseril MVP & Adobe Community Professional

                The very simplest script is:

                 

                this.getField("Address").value= this.getField("Text1").value + "\n" + this.getField("Text2").value + "\n" + this.getField("Text3").value + "\n" + this.getField("Text4").value;

                 

                "\n" including the quotation marks, is the character string for a new line. The "+" operator is the JavaScirpt concatenation operator and addition operator. The inclusion of a character string will force the values to string and concatenation. But an empty field will insert a blank line.

                 

                With the following document level function one can join the strings and eliminate the empty fields.

                 

                // Concatenate 3 strings with separators where needed

                function fillin(s1, s2, s3, sep) {
                  var test = 0;

                  s1 = s1.toString();
                  s2 = s2.toString();
                  s3 = s3.toString();

                  if (s1 != "") test += 4;
                  if (s2 != "") test += 2;
                  if (s3 != "") test += 1;

                  if (test == 0) return "";
                  if (test == 1) return s3;
                  if (test == 2) return s2;
                  if (test == 3) return s2 + sep + s3;
                  if (test == 4) return s1;
                  if (test == 5) return s1 + sep + s3;
                  if (test == 6) return s1 + sep + s2;
                  if (test == 7) return s1 + sep + s2 + sep + s3;
                }

                 

                For the "Address" form field, one could use the following custom calculation script:

                 

                event.value = fillin(this.getField("Text1").value, this.getField("Text2").value, this.getField("Text3").value, "\n");
                event.value = fillin(event.value, this.getField("Text4").value, "", "\n");

                If you have the distribution DVD/CD for Acrobat, there are sample folders and addtional documentation on that disk.

                1 person found this helpful