6 Replies Latest reply on Mar 29, 2011 1:46 PM by kbowers000

    Bill to Address same as Ship to

    kbowers000

      I'm new to JavaScripting and I'm trying to create a PDF form that has a check box that when checked will auto fill information.  Specifically, when the user fills out the bill to address they can click the check box "same as billing" and it will populate the ship to address.  Any advice would be greatly appreciated.   

       

      My data fields are as follows:

       

      BTName

      Billaddress1

      Billaddress2

      BillCity

      BillState

      BillZIP

       

      SAMEAS (this is the check box)

       

      STName

      ShipAddress1

      ShipAddress2

      ShipCity

      ShipState

      ShipZIP

       

      My JavaScript that I added to the check box is as follows:

       

      // check the state of the button
      if(this.getField('SAMEAS').value == '1') {
      // checked
      // copy requestor information
      // get each requestor field object's value and set the sponsor field's value
      this.getField('BTName').value = this.getField('STName').value;
      this.getField('BillAddress1').value = this.getField('ShipAddress1').value;
      this.getField('BillAddress2').value = this.getField('ShipAddress2').value;
      this.getField('BillCity').value = this.getField('ShipCity').value;
      this.getField('BillState').value = this.getField('ShipState').value;
      this.getField('BillZIP').value = this.getField('ShipZip').value;
      }

        • 1. Re: Bill to Address same as Ship to
          George_Johnson MVP & Adobe Community Professional

          I would suggest changing this line:

           

          if(this.getField('SAMEAS').value == '1') {

           

          to this:

           

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

           

           

          Also, you should get the field values using the valueAsString property, especially for the ZIP code:

           

          this.getField('BillZIP').value = this.getField('ShipZip').valueAsString;

           

          This ensures that any leading zeroes are retained for numeric entries.

           

           

          You placed the script in the check box's Mouse Up event, right? If not, you should. You didn't mention what the problem is. Does the code not do anything?

          • 2. Re: Bill to Address same as Ship to
            gkaiseril MVP & Adobe Community Professional

            You have to make sure you are matching to the export value of the check box, the unchecked value, or the 'isBoxChecked' property of the widget.

             

            The default export value for a check box in Acrobat is "Yes" and the unchecked value is "Off". The use of the 'isBoxChecked' is a little more complex and has issues if there is more than one check box.

             

            As George Johnson has suggested checking for the value not equal to 'Off' is the easiest technique.

            • 3. Re: Bill to Address same as Ship to
              kbowers000 Level 1

              Sorry for not mentioning the problem...I was actually not getting anything to happen.  I do have the trigger to be mouse up, and run JavaScript.  Now with the updated script when I check the box it clears all the bill to address info and nothing appears in the shipping fields?  Thanks so much for the quick response.  

               

               

              I just updated the script to the following:

               

              // check the state of the button
              if(event.target.value !== 'OFF') {
              // checked
              // copy requestor information
              // get each requestor field object's value and set the sponsor field's value
              this.getField('BTName').value = this.getField('STName').valueAsString;
              this.getField('BillAddress1').value = this.getField('ShipAddress1').valueAsString;
              this.getField('BillAddress2').value = this.getField('ShipAddress2').valueAsString;
              this.getField('BillCity').value = this.getField('ShipCity').valueAsString;
              this.getField('BillState').value = this.getField('ShipState').valueAsString;
              this.getField('BillZIP').value = this.getField('ShipZip').valueAsString;
              }

              • 4. Re: Bill to Address same as Ship to
                try67 MVP & Adobe Community Professional

                The value of a check-box when not selected is "Off", not "OFF". It's

                case-sensitive.

                • 5. Re: Bill to Address same as Ship to
                  kbowers000 Level 1

                  Thanks to all I figured this out my fields were reversed all is working!! here was the final script.

                   

                  // check the state of the button
                  if(event.target.value !== 'Off') {
                  // checked
                  // copy requestor information
                  // get each requestor field object's value and set the sponsor field's value
                  this.getField('STName').value = this.getField('BTName').valueAsString;
                  this.getField('ShipAddress1').value = this.getField('BillAddress1').valueAsString;
                  this.getField('ShipAddress2').value = this.getField('BillAddress2').valueAsString;
                  this.getField('ShipCity').value = this.getField('BillCity').valueAsString;
                  this.getField('ShipState').value = this.getField('BillState').valueAsString;
                  this.getField('ShipZIP').value = this.getField('BillZip').valueAsString;
                  }

                  • 6. Re: Bill to Address same as Ship to
                    kbowers000 Level 1

                    This is closed thanks to all.