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

pdf form conditional checkboxes

New Here ,
Feb 26, 2011 Feb 26, 2011

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!

38.1K
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
1 ACCEPTED SOLUTION
LEGEND ,
Feb 26, 2011 Feb 26, 2011

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();

View solution in original post

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
LEGEND ,
Feb 26, 2011 Feb 26, 2011

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();

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
New Here ,
Feb 26, 2011 Feb 26, 2011

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!!!

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
New Here ,
Feb 27, 2011 Feb 27, 2011

:-}

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

This seems not working on acrobat dc?

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
Guest
Mar 01, 2015 Mar 01, 2015

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!

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