3 Replies Latest reply on Feb 14, 2008 3:00 PM by gkaiseril

    Suppress Blank Lines

      I created a pdf which the user enters data into fields (name, address, city, state, etc). The results of the fields are used to auto populate an "Mail To" field which is used to send out the pdf. Now for my question: is there a way to combine all the fields together so they are presented as:

      Title FirstName LastName Suffix
      Addr One
      Addr Two (present only if valued; suppress field/blank field if not valued.
      City, State Postal Code

      I currently use the following code to present the name field:

      var MEMTITLE = this.getField("MEMBER.TITLE");
      var MEMFN = this.getField("REQUIRED.MEMBER.FNAME");
      var MEMMI = this.getField("MEMBER.MI");
      var MEMLN = this.getField("REQUIRED.MEMBER.LNAME");
      var MEMSUF = this.getField("MEMBER.SUFFIX");
      this.getField("READONLY.REQUIRED.MEMBER.FULLNAME").value = MEMTITLE.value + " " + MEMFN.value + " " + MEMMI.value + " " + MEMLN.value + " " + MEMSUF.value;

      I can do the same for the address, but do not know if it is possible to evaluate if the addr2 field is valued and suppress the space if not.

      Any advise/insight would be great. I am new to javascript!
        • 1. Re: Suppress Blank Lines
          gkaiseril MVP & Adobe Community Professional
          Have you looked at the PFN examples provided with the distribution CD. Within the PFNForm.pdf there is a document level script, "fillin(s1, s2, s3, se[)" to concatenate up to 3 variables and an optional separator and eliminate blank data from the concatenation.
          • 2. Re: Suppress Blank Lines
            Level 1
            var testAltAddr = this.getField("CALC.ALT_ADDR_EXISTS")
            if ((testAltAddr.value =="No") && (this.getField("MEMBER.PERM_ADDR_L2").value.length != 0))
            {var Add=getField("READONLY.REQUIRED.ADDRESS");
            Add.display=display.visible;
            var ADD1=this.getField("REQUIRED.MEMBER.PERM_ADDR_L1");
            var ADD2 =this.getField ("MEMBER.PERM_ADDR_L2");
            var CITY=this.getField("REQUIRED.MEMBER.PERM_ADDR_CITY");
            var STATE = this.getField ("REQUIRED.MEMBER.PERM_ADDR_STATE");
            var ZIP = this.getField ("REQUIRED.MEMBER.PERM_ADDR_ZIP");
            this.getField ("READONLY.REQUIRED.ADDRESS").value = ADD1.value + "\n" + ADD2.value + "\n" + CITY.value + ", " + STATE.value + " " + ZIP.valueAsString;
            }
            else if ((testAltAddr.value =="No") && (this.getField("MEMBER.PERM_ADDR_L2").value.length == 0))
            {
            var Add=getField("READONLY.REQUIRED.ADDRESS");
            Add.display=display.visible;
            var ADD1=this.getField("REQUIRED.MEMBER.PERM_ADDR_L1");
            var CITY=this.getField("REQUIRED.MEMBER.PERM_ADDR_CITY");
            var STATE = this.getField ("REQUIRED.MEMBER.PERM_ADDR_STATE");
            var ZIP = this.getField ("REQUIRED.MEMBER.PERM_ADDR_ZIP");
            this.getField ("READONLY.REQUIRED.ADDRESS").value = ADD1.value + "\n" + CITY.value + ", " + STATE.value + " " + ZIP.valueAsString;
            }
            else
            {
            var Add=getField("READONLY.REQUIRED.ADDRESS");
            Add.display=display.hidden;
            var AltAdd=getField("READONLY.REQUIRED.ALTADDRESS");
            AltAdd.display=display.visible;}
            • 3. Re: Suppress Blank Lines
              gkaiseril MVP & Adobe Community Professional
              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) {
              /* concatenate up to 3 strings
              input: 3 character strings and a separator to be placed
              between the 3 strings
              returns: the 3 inputted strings separated by the separator
              character
              */

              // variable to determine how to concatenate the strings
              var test = 0; // all strings null

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

              // compute which test to run based on non-null input strings
              if (s1 != "") test += 1; // string 1 present
              if (s2 != "") test += 2; // string 2 present
              if (s3 != "") test += 4; // string 3 present

              // return appropriate string combination based on calculated test value
              if (test == 0) return ""; // no string passed
              if (test == 1) return s1; // only string 1 present
              if (test == 2) return s2; // only string 2 present
              if (test == 3) return s1 + sep + s2; // string 1 and 2 present
              if (test == 4) return s3; // only string 3 present
              if (test == 5) return s1 + sep + s3; // string 1 and 3
              if (test == 6) return s2 + sep + s3; // string 2 and 3
              if (test == 7) return s1 + sep + s2 + sep + s3; // all 3 strings
              }

              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":

              var MEMTITLE = this.getField("MEMBER.TITLE");
              var MEMFN = this.getField("REQUIRED.MEMBER.FNAME");
              var MEMMI = this.getField("MEMBER.MI");
              var MEMLN = this.getField("REQUIRED.MEMBER.LNAME");
              var MEMSUF = this.getField("MEMBER.SUFFIX");

              var MEMFULLNAME = fillin(MEMTITLE.value, MEMFN.value, MEMMI.value, " "); // combine upto 3 strings separated by a space
              event.value = fillin(MEMFULLNAME, MEMLN, MEMSUF, ", "); // now add the last name and suffix