Skip to main content
Inspiring
May 12, 2023
Answered

Any number of checkboxes unhides a button, rehides it when not selected

  • May 12, 2023
  • 1 reply
  • 996 views

Hi there! I am attempting to code a set of checkboxes to unhide a button when they are checked. It's not a 1:1 correlation, so in my sample that I'm playing with, I have Check1, Check2, Check3, Check4, Check5. If Checks 1, 3, or 5 are checked, I want Button1 to unhide. If all 3 of those checkboxes are unchecked, I want Button1 to hide again. I have been fiddling with the code, and I thought this was the answer, but it's not functioning correctly (it's set as a Mouse Up event) and now I'm stuck. Thanks in advance for your assistance!

 

var r1 = this.getField("Check1").valueAsString;
var r2 = this.getField("Check3").valueAsString;
var r3 = this.getField("Check5").valueAsString;

if (event.r1 != "Off" || event.r2 != "Off" || event.r3 != "Off") {
this.getField("Button1").display = display.visible ;
} else {
this.getField("Button1").display = display.hidden ;
}
This topic has been closed for replies.
Correct answer Thom Parker

#1, first thing to do, Make up a table that shows the relationship between the checkbox states and the button states. 

 

#2. For the case you've described, and the code you've posted. 

There is no "event.r1", it's just "r1" as declared at the top of the script. 

 

var r1 = this.getField("Check1").valueAsString;
var r2 = this.getField("Check3").valueAsString;
var r3 = this.getField("Check5").valueAsString;

this.getField("Button1").display = ((r1 != "Off") || (r2 != "Off") || (r3 != "Off"))?display.visible:display.hidden;

 

 

  

1 reply

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
May 12, 2023

#1, first thing to do, Make up a table that shows the relationship between the checkbox states and the button states. 

 

#2. For the case you've described, and the code you've posted. 

There is no "event.r1", it's just "r1" as declared at the top of the script. 

 

var r1 = this.getField("Check1").valueAsString;
var r2 = this.getField("Check3").valueAsString;
var r3 = this.getField("Check5").valueAsString;

this.getField("Button1").display = ((r1 != "Off") || (r2 != "Off") || (r3 != "Off"))?display.visible:display.hidden;

 

 

  

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Inspiring
May 12, 2023

Marvelous, that works beautifully!

 

And yes, I am definitely building a table because it's actually 12 different checkboxes controlling 7 different buttons and I'll need to keep it straight! (Plus the checkboxes fire off statements in 7 different summary boxes.) Organization for sure!

 

Thank you so very much for your help!