• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

button on click show/hide other fields

Explorer ,
Feb 21, 2018 Feb 21, 2018

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.

TOPICS
Acrobat SDK and JavaScript , Windows

Views

7.3K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 22, 2018 Feb 22, 2018

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;

Votes

Translate

Translate
Community Expert ,
Feb 21, 2018 Feb 21, 2018

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

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 22, 2018 Feb 22, 2018

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 22, 2018 Feb 22, 2018

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;

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jun 19, 2018 Jun 19, 2018

Copy link to clipboard

Copied

LATEST

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):

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines