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

Checkbox checked, then two other checkboxes become both unchecked and disabled/read-only

Explorer ,
Mar 08, 2018 Mar 08, 2018

Hi

In my pdf form I have three checkboxes named: checkbox1, checkbox2 and checkbox3.

I wish the following to happen:

If checkbox1 is checked, then checkbox2 and checkbox3 become unchecked/cleared (if they were previously checked), but at the same time checkbox 2 and checkbox3 also become disabled/read-only (by disabled I mean not checkable, not clickable, just read-only).

I have a javascript that does kind of the opposite (which I earlier got help with on this forum on a similar but different case).

It looks like this: checkbox1 checked then checkbox2 and checkbox 3 become checked and disabled/read-only.

And the script for this looks like this:

on the MouseUp script for "checkbox1".

this.getField("checkbox2").value = event.target.value;

this.getField("checkbox2").readonly = (event.target.value == "Yes");

this.getField("checkbox3").value = event.target.value;

this.getField("checkbox3").readonly = (event.target.value == "Yes");

So as a rookie I have tried to experiment with this script as a base but no solution so far.

Appreciate your help on this

/Dennis

TOPICS
PDF forms
24.0K
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
Community Expert ,
Mar 12, 2018 Mar 12, 2018

It is important to work through the logic.

When you say that checking 1 causes 2 to become unchecked if it was checked, but doesn't do anything if 2 is already unchecked. The result is that checking 1 always unchecks 2.  This is an important simplification when you go to write the code.

So here is a variation that only changes 2 & 3 (to unchecked) when 1 is checked, but leaves them untouched when 1 is unchecked

Notice that the export values for 2 & 3 are not used, since they are only being turned off (unchecked).  The code never checks 2 & 3.

var bChecked = (event.target.value == "Yes")

this.getField("checkbox3").readonly = bChecked;

this.getField("checkbox2").readonly = bChecked;

if(bChecked)

{

     this.getField("checkbox3").value = "Off";

     this.getField("checkbox2").value = "Off";

}

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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
Community Beginner ,
Sep 25, 2020 Sep 25, 2020

Thanks, I got it 🙂

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