Checkbox query! Javascript to prevent unchecking...
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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);
Copy link to clipboard
Copied
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";
}
Use the Acrobat JavaScript Reference early and often

