Copy link to clipboard
Copied
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.
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;
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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;
Copy link to clipboard
Copied
In case someone finds this useful, I have a checkbox that hides/shows a digital signature box (no button is used). The user cannot digitally sign until the box is checked. While unchecked, a statement is displayed instead of the digital signature box saying, "The checkbox must be checked before signing". Upon clicking the checkbox, the statement is hidden, and the signature box pops up. Note that I removed line 2 from the previous example, and in my example below, I switched the order of the arguments of line 3 to read "display.hidden : display.visible", so they would toggle in opposite sequence to line 2, so that when one shows, the other hides, and vice-versa.
var oChkFld = this.getField("checkbox");
this.getField("checkboxRequired").display = oChkFld.value=="Off" ? display.visible : display.hidden;
this.getField("Signature").display = oChkFld.value=="Off" ? display.hidden : display.visible;
Unclicked checkbox (can't sign):
Clicked checkbox (ready to sign):