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

If only cb1 is checked then cb4 is checked too

Community Beginner ,
Jul 22, 2023 Jul 22, 2023

Hello,

 

I came across another issue....

 

I have 3 checkboxes (CB1, CB2 and CB3)

I like CB4 to be checked when only CB3 is checked.

If any of the other combinations are checked (when cb1 and cb3 are checked or cb2 and cb3) cb4 needs to be unchecked.

i try using other scrips i found but i cant find the right solution.

For all of you masters here, it would be a piece of cake i guess 😉

TOPICS
How to , JavaScript
712
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 ,
Jul 22, 2023 Jul 22, 2023

Write out a table showing the state of the check boxes (forced checked, forced unchecked, and user controled) depending on what is checked. Cover all combinations. 

Use this to write scripts for the MouseUp event on each checkbox. 

 

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
Community Beginner ,
Jul 22, 2023 Jul 22, 2023

I dont know what you mean. im just learning....

the thing is, i only try to use scrips when there is no other way so its hard to put time in it to learn properly.

 

A start would be helpful 😉

 

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 ,
Jul 22, 2023 Jul 22, 2023

As the custom calculation script of a (hidden) text field enter the following code:

 

var CB1 = this.getField("CB1").valueAsString!="Off";
var CB2 = this.getField("CB2").valueAsString!="Off";
var CB3 = this.getField("CB3").valueAsString!="Off";

this.getField("CB4").checkThisBox(0, !CB1 && !CB2 && CB3);
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 Beginner ,
Jul 22, 2023 Jul 22, 2023

It worked perfectly thnx.....

but i made one misstake.....

CB4 isnt a checkbox but a radiobutton called Group4 and its the 3rd choice.

 

What wil be different?

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 ,
Jul 22, 2023 Jul 22, 2023

Yes, that will be different. What's the export value for the 3rd Choice? 

You can read about how radiobuttons and checkboxes work in Acrobat here:

https://www.pdfscripting.com/public/Checkboxes-and-Radio-Buttons.cfm

 

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
Community Beginner ,
Jul 22, 2023 Jul 22, 2023

the export value is Choice3

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 ,
Jul 22, 2023 Jul 22, 2023

Then this is how the code changes

 

var CB1 = this.getField("CB1").valueAsString!="Off";
var CB2 = this.getField("CB2").valueAsString!="Off";
var CB3 = this.getField("CB3").valueAsString!="Off";

if(!CB1 && !CB2 && CB3)
    this.getField("CB4").value = "Choice3";
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
Community Expert ,
Jul 23, 2023 Jul 23, 2023
LATEST

Do you want the user to be able to tick the other fields in the group, though? If so, that would require a different kind of script

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