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

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

Participant ,
May 12, 2023 May 12, 2023

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 ;
}
TOPICS
JavaScript , PDF , PDF forms
896
Translate
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
1 ACCEPTED SOLUTION
Community Expert ,
May 12, 2023 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 PDFScripting
Use the Acrobat JavaScript Reference early and often

View solution in original post

Translate
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 ,
May 12, 2023 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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
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
Participant ,
May 12, 2023 May 12, 2023
LATEST

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!

Translate
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