4 Replies Latest reply on Aug 26, 2014 2:26 PM by mslaughter0915

    Help with Javascript Code

    mslaughter0915

      I'm in need of some him writing a quick JavaScript code. I have no experience in JavaScript but understand enough to know what we need. I'm helping to write a very simple writeable document in Adobe Acrobat Pro. We need a code that would specific that when a checkbox is clicked it auto populates information in other text boxes. Simply put: if the mailing address matches the job address then it populates that information. I've included my variables with correct names below.

       

      Thanks for taking the time. Can anyone help?

       

       

       

       

      I need something that will:

      if checkbox = "On"

      then "Job Address1" = Address1

      then "Job City1" = City1

      then "Job State1" = State1

      then "Job Zip Code" = Zip Code1

      then "Job County" = County1

      then "Job City, State Zip1" = City, State Zip1

      else

      if checkbox = "Off"

      *each one of the first variables remains empty and writeable.

        • 1. Re: Help with Javascript Code
          gkaiseril MVP & Adobe Community Professional

          This if far from a quick or simple coding problem.


          There are 2 situations that would cause the job fields to be changed. A change in the individual page or a change in the check box. I am also not sure why you are not filling in the  "City, State, Zip1" field when you already have the values that are concatenated form the "City1", "State1", and "Zip1" fields.

           

          With the distribution CD/DVD for Acrobat Adobe has sample from and in the PFN directory has a file that concatenates up to 3 fields at one time and can optionally include a separator character and automatically adjust as needed for missing value and performs the task of combining individual name fields, address fields, and phone numbers.

           

          For the check box I would use a script like the following for the mouse up action:

           

          if(event.value != "Off") {

          // populate the job fields;

          this.getField("Job Address1").value  = this.getField("Address1").value;

          this.getField("Job City1").value; = this.getField("City1").value;

          this.getField("Job State1").value; = this.getField("State1").value;

          this.getField("Job Zip Code").value; = this.getField("Zip Code1").value;

          this.getField("Job County").value; = this.getField("County1").value;

          this.getField("Job City, State Zip1").value; = this.getField("City, State Zip1").value;

          else {

          // clear the fields;

          this.getField("Job Address1").value  = "";

          this.getField("Job City1").value; = "";

          this.getField("Job State1").value; = "";

          this.getField("Job Zip Code").value; = "";

          this.getField("Job County").value; = "";

          this.getField("Job City, State Zip1").value; = "";

          }

          • 2. Re: Help with Javascript Code
            mslaughter0915 Level 1

            Thank you so much for your help and explanation. This makes sense to me. I added the code it gave me a syntax error 7: at line 8. This is where I have no idea how to trouble shoot. Any thoughts? Thanks again

            • 3. Re: Help with Javascript Code
              gkaiseril MVP & Adobe Community Professional

              The lined the reads:

               

              this.getField("Job State1").value; = this.getField("State1").value;

               

              has a semicolon where it does not belong. The line should read:

               

              this.getField("Job State1").value; = this.getField("State1").value;

               

              Then the entire code is:

               

              if(event.value != "Off") {

              // populate the job fields;

              this.getField("Job Address1").value  = this.getField("Address1").value;

              this.getField("Job City1").value; = this.getField("City1").value;

              this.getField("Job State1").value = this.getField("State1").value;

              this.getField("Job Zip Code").value; = this.getField("Zip Code1").value;

              this.getField("Job County").value; = this.getField("County1").value;

              this.getField("Job City, State Zip1").value; = this.getField("City, State Zip1").value;

              else {

              // clear the fields;

              this.getField("Job Address1").value  = "";

              this.getField("Job City1").value; = "";

              this.getField("Job State1").value; = "";

              this.getField("Job Zip Code").value; = "";

              this.getField("Job County").value; = "";

              this.getField("Job City, State Zip1").value; = "";

              }

               

              You will have to work out how to adjust each individual field if only one is updated. The combined field may need to be updated by each component field. I would use the on blur action and avoid using the custom calculation action.

              • 4. Re: Help with Javascript Code
                mslaughter0915 Level 1

                Thank you so much. Got it working.