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

go through several checkboxes if all checked than check one checkbox

New Here ,
Mar 27, 2018 Mar 27, 2018

Copy link to clipboard

Copied

Hello,

I do not have much experience in Java, please help me.

I want to write such a command -> only if all checkboxes are checked then this checkbox "cb0" should be automaticaly checked.

What is false in my code?

var 1=getField("cb1").value;
var 2=getField("cb2").value;
var 3=getField("cb3").value;

for (i = 1; i < 3; i++){
   if(event.target.value=="Yes"){
    getField("cb0").checkThisBox(0,true);
}
    else if(event.target.value!=="Yes"){
     getField("cb0").checkThisBox(0,false);
      }
}

TOPICS
Acrobat SDK and JavaScript

Views

554

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 , Mar 27, 2018 Mar 27, 2018

Then use this code:

var allChecked = true;

for (var i=1; i<=100; i++) {

    var f = this.getField("cb"+i);

    if (f.valueAsString=="Off") {

        allChecked = false;

        break;

    }

}

this.getField("cb0").checkThisBox(0, allChecked);

Votes

Translate

Translate
Community Expert ,
Mar 27, 2018 Mar 27, 2018

Copy link to clipboard

Copied

- You can't define variables with just numbers. How would it know if you're referring a number or the variable?

- You don't need the for-loop.

- Where did you place this code? Why are you accessing the field's value?

Here's how to do it properly. Create a (hidden) text field and apply this code as its custom calculation script:

var v1 = this.getField("cb1").valueAsString;

var v2 = this.getField("cb2").valueAsString;

var v3 = this.getField("cb3").valueAsString;

this.getField("cb0").checkThisBox(0, v1!="Off" && v2!="Off" && v3!="Off");

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
New Here ,
Mar 27, 2018 Mar 27, 2018

Copy link to clipboard

Copied

I only tired. I just want, that one checkbox activate automatically, as soon as the other 100 checkboxes are checked

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
New Here ,
Mar 27, 2018 Mar 27, 2018

Copy link to clipboard

Copied

Atomatically check a checkbox if a group of others are checked

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 ,
Mar 27, 2018 Mar 27, 2018

Copy link to clipboard

Copied

100 check-boxes!? You wrote there were 3...

Well, that would require a different kind of script.

Are the names of these check-boxes "cb1", "cb2", etc. up to "cb100"?

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
New Here ,
Mar 27, 2018 Mar 27, 2018

Copy link to clipboard

Copied

yes I know, this is an example of three checkboxes

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
New Here ,
Mar 27, 2018 Mar 27, 2018

Copy link to clipboard

Copied

and yes cb1, cb2, .....cb100

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 ,
Mar 27, 2018 Mar 27, 2018

Copy link to clipboard

Copied

Then use this code:

var allChecked = true;

for (var i=1; i<=100; i++) {

    var f = this.getField("cb"+i);

    if (f.valueAsString=="Off") {

        allChecked = false;

        break;

    }

}

this.getField("cb0").checkThisBox(0, allChecked);

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
New Here ,
Mar 27, 2018 Mar 27, 2018

Copy link to clipboard

Copied

Sorry, but "cb0" needs to be checked automatically after the other 100 are checked. Do you know what I mean?

after all checkboxes checked, in "cb0" appears a check automatically

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 ,
Mar 27, 2018 Mar 27, 2018

Copy link to clipboard

Copied

Yes, that's what the code I provided does, if you use it as I've described.

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
LEGEND ,
Mar 27, 2018 Mar 27, 2018

Copy link to clipboard

Copied

LATEST

"cb0" is checked if the value of the variable "allChecked" is true else it is not checked. This is how the "checkThisBox()" method works. Follow the link in the previous sentence for more information from the Acrobat JavaScript Reference.

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