3 Replies Latest reply on Dec 31, 2014 11:05 AM by bw200

    Show/Hide fields based on checkbox

    bw200 Level 1

      A common question I know, however I am having an issue with the field labels.

       

      The PDF form was created with FormsCentral and then edited locally with Acrobat XI (version 11.0.10) on Windows 7 Pro.

       

      The PDF has a checkbox to allow the user to enter a separate shipping address. In the checkbox properties, Actions tab, I have Mouse Up as the trigger and the following JavaScript.

       

      var nHide = event.target.isBoxChecked(0)?display.visible:display.hidden;

      this.getField("SHIPPING ADDRESS").display = nHide;

      this.getField("CITY_2").display = nHide;

      this.getField("STATE / PROVINCE_2").display = nHide;

       

      this works well, however the field labels remain visible in the PDF regardless of the visible / hidden state.

       

      How can I hide the field labels along with the fields themselves when the checkbox remains unchecked?

       

      Thanks,

      bw200

        • 1. Re: Show/Hide fields based on checkbox
          try67 MVP & Adobe Community Professional

          Assuming the labels are just static text you can't hide them directly. What

          you can do, though, is place white fields on top of them and then show

          those fields when you want to hide the text underneath, and hide them when

          you want the text to be visible.

          • 2. Re: Show/Hide fields based on checkbox
            bw200 Level 1

            Many thanks Gilad, yep they are static text, your solution sounds viable.

            • 3. Re: Show/Hide fields based on checkbox
              bw200 Level 1

              For anyone who may benefit - this is what I did.

               

              In checkbox properties:

              Actions tab

              Select Trigger: Mouse Up

              Select Action: Run a JavaScript

               

              Here is the JS:

               

              // Show/hide alternate shipping address text fields

              var nHide = event.target.isBoxChecked(0)?display.visible:display.hidden;

              this.getField("SHIPPING ADDRESS").display = nHide;

              this.getField("CITY_2").display = nHide;

              this.getField("STATE / PROVINCE_2").display = nHide;

               

              // Show/hide alternate shipping address text field label overlays

              this.getField("Overlay_1").display = event.target.value == "Off"? display.visible: display.hidden;

              this.getField("Overlay_2").display = event.target.value == "Off"? display.visible: display.hidden;

              this.getField("Overlay_3").display = event.target.value == "Off"? display.visible: display.hidden;

               

              So the overlay simply refers to three text fields I added to the PDF form, which cover the labels for the three text fields that are hidden/visible for use as an alternate shipping address. The properties of these overlay text fields in the Appearance tab ensure the border color and fill color, (there is no text), match my document's background. Then, under the General tab, provide a name (i.e. Overlay_1, etc.), no tooltip needed, and then check Read Only. This last bit will ensure that when the user selects Highlight Existing Fields (upper right corner in green bar), these three overlay fields don't appear in the document (they just look strange and confusing if they do).