3 Replies Latest reply on Feb 22, 2018 9:29 AM by Thom Parker

    button on click show/hide other fields

    gamzes93533812 Level 1

      Hi,

      I have a button created on my Acrobat Form, and I would like to use this button to show/hide some other fields.

      So basically, if user click once, it will display some other fields, and if clicks for the second time it will again hide fields.

       

      If it was a checkbox, I could simply assign a mouse up event as follows to solve the issue:

       

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

       

       

      But which kind of script and event is required for button? I simply could not solve it out.

        • 1. Re: button on click show/hide other fields
          Thom Parker Adobe Community Professional

          To do this you need to save a "state" value.  A checkbox works because it maintains the "state" as the checkbox value. With a button there is no "state", as you've already found out. An easy solution is to  use a document level variable, but if the form is saved and then reopened the "state" is lost because the document variable value is lost. So if it is important for this to work after a document is closed, then you need a way to save the "state" with the document. The best solution is to use a hidden check box.  Each time the button is clicked it toggle the value of the hidden check and sets the visibility accordingly, just like you're script above

          1 person found this helpful
          • 2. Re: button on click show/hide other fields
            gamzes93533812 Level 1

            Thank you for making the reasons very clear. Yes, it's important for this to work after the doc is closed!

            I wanted to apply the "hidden check box" idea. Forgive my ignorance but how to assign the button on click function that will check/uncheck dependent checkbox?

            • 3. Re: button on click show/hide other fields
              Thom Parker Adobe Community Professional

              You just need to put your existing script in to the MouseUp for the button and modify it. And of course you also need to add a hidden checkbox to the form.

               

              var oChkFld = this.getField("HiddenCheck");
              oChkFld.checkThisBox(0,!oChkFld.isBoxChecked(0));
              this.getField("myfieldtoshowhide").display = (oChkFld.value=="Off") ? display.hidden : display.visible;
              
              1 person found this helpful