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

Would like option of one checkbox that would automatically check multiple checkboxes

Community Beginner ,
Dec 17, 2020 Dec 17, 2020

Hi there,

I have multiple checkboxes (named "CheckBox1", "Checkbox2", and "CheckBox3")

 

I would like it so that the end-user can individually check these checkboxes and they have the option to click a separate checkbox (let's name it "CheckBoxAll") so that all of the checkboxes are checked and the CheckBox1, 2, and 3 are also locked.  If the CheckBoxAll is then unchecked, it will revert back to all boxes being unchecked.

 

I'm guessing I would want a Mouse Up JavaScript in the CheckBoxAll checkbox, but I can't figure out what to put in there.

 

Any ideas?  Thanks in advance.
Glenn

TOPICS
PDF forms
703
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 ,
Dec 17, 2020 Dec 17, 2020

Yes, use MouseUp in CheckBoxAll:

if(event.target.isBoxChecked(0)){
this.getField("Checkbox1").checkThisBox(0,true);
this.getField("Checkbox1").readonly = true;
this.getField("Checkbox2").checkThisBox(0,true);
this.getField("Checkbox2").readonly = true;
this.getField("Checkbox3").checkThisBox(0,true);
this.getField("Checkbox3").readonly = true;}
else{
this.getField("Checkbox1").checkThisBox(0,false);
this.getField("Checkbox1").readonly = false;
this.getField("Checkbox2").checkThisBox(0,false);
this.getField("Checkbox2").readonly = false;
this.getField("Checkbox3").checkThisBox(0,false);
this.getField("Checkbox3").readonly = false;}

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 ,
Dec 17, 2020 Dec 17, 2020

You can set a field to read-only to prevent a user from interacting with it. The code for a single checkbox can be as simple as:

 

getField("Checkbox1").readonly = true;

 

and you can set it to false to make it user selectable.

 

The code can be simplified if you use hierarchcal naming for the group of checkboxes (e.g., group1.cb1, group1.cb2, etc.) and the code to disable all in the group can be:

 

getField("group1").readonly = true;

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 ,
Dec 17, 2020 Dec 17, 2020

Yes, use MouseUp in CheckBoxAll:

if(event.target.isBoxChecked(0)){
this.getField("Checkbox1").checkThisBox(0,true);
this.getField("Checkbox1").readonly = true;
this.getField("Checkbox2").checkThisBox(0,true);
this.getField("Checkbox2").readonly = true;
this.getField("Checkbox3").checkThisBox(0,true);
this.getField("Checkbox3").readonly = true;}
else{
this.getField("Checkbox1").checkThisBox(0,false);
this.getField("Checkbox1").readonly = false;
this.getField("Checkbox2").checkThisBox(0,false);
this.getField("Checkbox2").readonly = false;
this.getField("Checkbox3").checkThisBox(0,false);
this.getField("Checkbox3").readonly = 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 Beginner ,
Dec 17, 2020 Dec 17, 2020

Yet again to the rescue!  Thank you Nesa.
CheckBoxes 1, 2, and 3 also have their own scripts and I was hoping that when the above CheckBoxAll script ran that the individual scripts in CheckBox1, 2, and 3 would then run too...But they didn't...Probably because I didn't specify they needed to!!!
I tested the following (with the first checkbox) which seemed to work, and I just wondered if by doing this format for the remaining checkboxes is this the best/only way, or is there an easier way for this to work?

 

if(event.target.isBoxChecked(0)){

this.getField("CheckBoxNA7.1").checkThisBox(0,true);

this.getField("CheckBoxNA7.1").readonly = true; }

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

this.getField("Score7.1").value = "";

this.getField("CheckBoxD7.1").value = "Off";

this.getField("CheckBoxD7.1").readonly = true;}

else

this.getField("CheckBoxNA7.1").checkThisBox(0,false);

this.getField("CheckBoxNA7.1").readonly = false;

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

this.getField("Score7.1").value = 3;

this.getField("CheckBoxD7.1").readonly = 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
Enthusiast ,
Dec 18, 2020 Dec 18, 2020

It won't run script automatically,if you set up script in MouseUp event then you need to click on field to activate script.

If you want to run that script when "CheckBoxAll" is clicked then add script to "CheckBoxAll" MouseUp event, or make hidden text field and put script in "Custom calculaton script" so it will execute automatically.

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 ,
Dec 18, 2020 Dec 18, 2020
LATEST

That makes perfect sense.  Thank you.

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