Copy link to clipboard
Copied
Hi.
I'm building a pdf form in Acrobat 8 Professional. I want to add JavaScript to 3 checkboxes to achieve the following:
if checkbox 1 or 2 is checked, uncheck checkbox 3; and if checkbox 3 is checked uncheck both 1 and 2.
It seems straightforward, but I have not been able to find a solution either in the Acrobat guide nor online. I have no experience in Javascript other than copying and pasting, so I'm not sure I'm using the right language to search. If anyone can provide any guidance, I would greatly appreciate it.
Thanks a lot!
Copy link to clipboard
Copied
You could create a function in a document-level JavaScript and call it in the Mouse Up event of each check box, something like:
// Document-level function
function cbControl() {
// Get a reference to each check box
var f1 = getField("cb1");
var f2 = getField("cb2");
var f3 = getField("cb3");
// Uncheck cb3 if cb1 or cb2 was selected/deselected
if (event.target === f1 || event.target === f2) {
f3.value = "Off";
return;
}
// Uncheck cb1 and cb2 if cb3 was selected/deselected
if (event.target === f3) {
f1.value = "Off";
f2.value = "Off";
}
}
Change "cb1", "cb2", "cb3" to the names of the check boxes you're using.
Here's the code for each check box's Mouse Up event:
cbControl();
Copy link to clipboard
Copied
You could create a function in a document-level JavaScript and call it in the Mouse Up event of each check box, something like:
// Document-level function
function cbControl() {
// Get a reference to each check box
var f1 = getField("cb1");
var f2 = getField("cb2");
var f3 = getField("cb3");
// Uncheck cb3 if cb1 or cb2 was selected/deselected
if (event.target === f1 || event.target === f2) {
f3.value = "Off";
return;
}
// Uncheck cb1 and cb2 if cb3 was selected/deselected
if (event.target === f3) {
f1.value = "Off";
f2.value = "Off";
}
}
Change "cb1", "cb2", "cb3" to the names of the check boxes you're using.
Here's the code for each check box's Mouse Up event:
cbControl();
Copy link to clipboard
Copied
OMG!!!! Who are you?! It works perfectly -- you are amazing. Thank you so so so much! I was expecting many more hours of agonizing over this -- I can't thank you enough!!!
Copy link to clipboard
Copied
:-}
Copy link to clipboard
Copied
This seems not working on acrobat dc?

Copy link to clipboard
Copied
Well, a little bit late but thanks for this anyway. Very helpful.
I've another question related to this matter. How can I make polish this code and apply to various groups of checkboxes without creating an endless list of variables?
function Caselles()
{
// Get a reference to each check box
var f1 = getField("C1");
var f2 = getField("C2");
var f3 = getField("C3");
var f4 = getField("C4");
var f5 = getField("C5");
// Uncheck c2, c3 and c4 if c1 was selected/deselected
if (event.target === f1) {
f2.value = "Off";
f3.value = "Off";
f4.value = "Off";
}
// Uncheck c3 and c4 and check c1 when c2 was selected/deselected
if (event.target === f2) {
f1.checkThisBox(0,true);
f3.value = "Off";
f4.value = "Off";
}
// Uncheck c4 and check c1 and c2 when c3 was selected/deselected
if (event.target === f3) {
f1.checkThisBox(0,true);
f2.checkThisBox(0,true);
f4.value = "Off";
}
// Check all when c4 was selected/deselected
if (event.target === f4) {
f1.checkThisBox(0,true);
f2.checkThisBox(0,true);
f3.checkThisBox(0,true);
}
}
Thanks in advance!

