Copy link to clipboard
Copied
Hi there,
I want to set up a checkbox which when selected will automatically select some other checkboxes (these checkboxes have a java script that makes a field visible) and make hidden field visible at the same time.
Main checkbox = cycle1overall
Other checkboxes = Cycle1_1, Cycle1_2, Cycle1_3, Cycle1_4
the script for the hidden field is as follwed:
var f=this.getField("Cycle1_1");
var s=(f.value.length>0);function checkCheckbox(){
if (this.getField("Cycle1_1").isBoxChecked(0) == true) {
this.getField("Cycle1text1").display = display.visible;
this.getField("Cycle1text2").display = display.visible;
this.getField("Cycle1text3").display = display.visible;
} else {
this.getField("Cycle1text1").display = display.hidden;
this.getField("Cycle1text2").display = display.hidden;
this.getField("Cycle1text3").display = display.hidden;
}
}
checkCheckbox();
What script do i need to input int he maincheckbox so that it selects the Cycle1_1, Cycle1_2 checkboxes but also activates their javascript at the same time?
Thank you!
Copy link to clipboard
Copied
Unfortunately Acrobat only provides direct access to the UI events for a checkbox. These event are only triggered when the user clicks on the checkbox. They don't help with value changes. So for example, setting the value of a checkbox with a script does not trigger any UI events. You didn't say, but I imagine you are using the MouseUp event. Useless in this scenario.
There is also no way in the Acrobat JavaScript model to force the activation of a UI event.
So you have two solutions:
1. Place your scripts into the difficult to access validate event on the checkboxes.
2. Just execute all the code you need in the main checkbox.
I think #2 is the best solution.
On another note, you 've got some issues in your code.
var f=this.getField("Cycle1_1");
var s=(f.value.length>0);
If "Cycle1_1" is a checkbox then it's value will never have a length of 0. The value of a check box is either the export vaue (when checked) or off. Also, this code does not appear to do anything.
Next, why is the function defined? If this is code that's in a checkbox event then there's no point. Functions are used to abstract functionality to simplify scripting and/or make the functionality availible in multiple locations.
Read this article on checkboxes.
https://www.pdfscripting.com/public/Checkboxes-and-Radio-Buttons.cfm
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
Unfortunately Acrobat only provides direct access to the UI events for a checkbox. These event are only triggered when the user clicks on the checkbox. They don't help with value changes. So for example, setting the value of a checkbox with a script does not trigger any UI events. You didn't say, but I imagine you are using the MouseUp event. Useless in this scenario.
There is also no way in the Acrobat JavaScript model to force the activation of a UI event.
So you have two solutions:
1. Place your scripts into the difficult to access validate event on the checkboxes.
2. Just execute all the code you need in the main checkbox.
I think #2 is the best solution.
On another note, you 've got some issues in your code.
var f=this.getField("Cycle1_1");
var s=(f.value.length>0);
If "Cycle1_1" is a checkbox then it's value will never have a length of 0. The value of a check box is either the export vaue (when checked) or off. Also, this code does not appear to do anything.
Next, why is the function defined? If this is code that's in a checkbox event then there's no point. Functions are used to abstract functionality to simplify scripting and/or make the functionality availible in multiple locations.
Read this article on checkboxes.
https://www.pdfscripting.com/public/Checkboxes-and-Radio-Buttons.cfm
Use the Acrobat JavaScript Reference early and often

