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);
}
}
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);
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");
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
Copy link to clipboard
Copied
Atomatically check a checkbox if a group of others are checked
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"?
Copy link to clipboard
Copied
yes I know, this is an example of three checkboxes
Copy link to clipboard
Copied
and yes cb1, cb2, .....cb100
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);
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
Copy link to clipboard
Copied
Yes, that's what the code I provided does, if you use it as I've described.
Copy link to clipboard
Copied
"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.