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

Checkbox query! Javascript to prevent unchecking...

New Here ,
Jan 08, 2025 Jan 08, 2025

Hi, 

I'm new to adobe acrobat interactive PDFs but there are so many helpful posts here that have got me a long way! I currently have a number of checkboxes for different courses (eg. Course1, Course2) which check proficiencies in a list:

- Course1 checkbox: ticks proficiencies M1.1, M1.2, M1.4

- Course2 checkbox: ticks proficiencies M1.1, M1.6, M1.7

 

Currently if someone unchecks Course1, this will uncheck box 1.1 even if Course2 is still checked. Is there a way to prevent this?

 

I'm just using this code in Course1 checkbox on MouseUp:

this.getField("M1.1").value = event.target.value;
this.getField("M1.2").value = event.target.value;
this.getField("M1.4").value = event.target.value;

 

And this code in Course2 checkbox on MouseUp:

this.getField("M1.1").value = event.target.value;
this.getField("M1.6").value = event.target.value;
this.getField("M1.7").value = event.target.value;

 

Thanks in advance!

Lucy

TOPICS
Acrobat SDK and JavaScript
123
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 Expert ,
Jan 08, 2025 Jan 08, 2025

There are couple of ways you can achieve this, here is one:
Remove all Mouse UP scripts and place this in one (any) text field as custom calculation script:

var c1 = this.getField("Course1").valueAsString;
var c2 = this.getField("Course2").valueAsString;
this.getField("M1.1").checkThisBox(0,(c1 !== "Off" || c2 !== "Off")? true : false);
this.getField("M1.2").checkThisBox(0,(c1 !== "Off")? true : false);
this.getField("M1.4").checkThisBox(0,(c1 !== "Off")? true : false);
this.getField("M1.6").checkThisBox(0,(c2 !== "Off")? true : false);
this.getField("M1.7").checkThisBox(0,(c2 !== "Off")? true : false);
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 Expert ,
Jan 08, 2025 Jan 08, 2025
LATEST

So, you want the "Course" checkboxes to only turn other checkboxes On, but never Off. 

There are many ways to do this. Nesa suggested a universal calculation script. 

Here is another method

 

Mouseup for Course 1

if(event.target.value != "Off"){

    this.getField("M1.1").value ="Yes";
    this.getField("M1.2").value = "Yes";
    this.getField("M1.4").value ="Yes";

}

 

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

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