3 Replies Latest reply on Jul 7, 2011 11:46 AM by MarkWalsh

    Same as above checkbox with javascript

    andrew_m_j

      Hey all, I'm trying to set up a billing form in Acrobat Pro.  I have two address areas but I have a Same as Above checkbox to allow the user to copy their billing address to the shipping address.  I'm not sure what scripting I need or where to put it but I want it to check whether or not the box is checked, and if so, copy the billing address information to the shipping address area and lock them for editing.

       

      Here are the fields I have:

      BillingFullName

      BillingAddress1

      BillingCity

      BillingState

      BillingZip

      ShippingFullName

      ShippingAddress1

      ShippingCity

      ShippingState

      ShippingZip

       

      and my checkbox SameAsAbove.

       

      Thanks!

        • 1. Re: Same as above checkbox with javascript
          BarlaeDC Level 4

          HI,

           

          You could just put your code on the mouse up event of the check box and have code something like this

           

          this.getField("ShippingFullName").value = this.getField("BillingFullName").value

          // repeat for all the fields

           

          You could also check if the check box is now checked or not using event.value and then you could have an if statement something like

           

          if ( event.value = "Yes")

          {

               this.getField("ShippingFullName").value = this.getField("BillingFullName").value

               // repeat for all second address fields.

          }

          else

          {

               this.getField("ShippingFullName").value = "";

               // repeat for all second address fields.

          }

           

          (note: the above code was typed straight of the top of my head and I haven't checked it but the idea is there)

           

          Hope this helps

           

          Malcolm

          • 2. Re: Same as above checkbox with javascript
            George_Johnson MVP & Adobe Community Professional

            When you copy a field value from one field to another, be sure to retrieve the values using the valueAsString property. Otherwise, leading zeroes for fields containing just numbers will get trimmed. So if the user entered a Zip code of "01234", it would get copied as "1234". So do something like:

             

            this.getField("ShippingZip").value = this.getField("BillingZip").valueAsString;

            • 3. Re: Same as above checkbox with javascript
              MarkWalsh Level 4

              Here's what I'd do:

               

              In the MouseUp event of the checkbox (named 'SameAsAbove' here), put the following:

               

              this.calculateNow

               

              In the 'Calculate' event of the ShippingFullName field (and all other shipping fields), put the following:

               

              event.value = event.value

               

              In the 'Format' event of the ShippingFullName field (and all other shipping fields), put the following:

               

              if (this.getField("SameAsAbove").value == 'Yes') {
              event.value = this.getField("BillingFullName").valueAsString
              }

               

              This way, if they click the 'SameAsAbove' checkbox it will display the billing address (without changing the shipping value they may have entered), but if they uncheck it, the original shipping value entered is shown.

               

               

               

              Edit: the CalculateNow command may not be necessary, but it doesn't hurt to keep it in

              Edit2 to add 'valueAsString' as suggested by George above.