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

Checkbox behavior enables or disables other checkboxes

New Here ,
Dec 12, 2020 Dec 12, 2020

Copy link to clipboard

Copied

Hello,

 

I've looked through many posts on this topic and have found some solutions, but one thing is not functioning correctly.  I have a Yes/No checkbox, and A/B/C checkboxes that I want to be disabled unless Yes is checked:

  1. A/B/C checkboxes disabled / read-only on form entry
  2. If Yes is checked, A/B/C checkboxes become enabled
  3. If No is checked, A/B/C checkboxes are cleared and become disabled

 

It was working, but what was happening was that the Yes button was enabling the boxes only if the No button had been clicked to check OFF, but not if the Yes button was clicked, toggling the ON No button (No button had to be checked OFF for the Yes button to enable the fields). 

 

Unfortunately, I can't recreate the state noted above, so I didn't want to post the script, but I could if needed to help.

 

Thanks in advance!

TOPICS
JavaScript

Views

6.0K

Translate

Translate

Report

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

Copy link to clipboard

Copied

 

There many ways to do this with JavaScript scripting.

 

In my example below I named the checkboxes for yes and no with the same field name "myCheckBox" and then I set  them up each one  with a different export value for example: "Choice1", and "Choice2" respectively.

 

For the 3 checkboxes A, B, and C I created them and named them as shown in the scripts below and also set their field property to read-only (as default): 

 

  • in myCheckBox with export value of "Choice1" I used this script

 

 

if (event.target.valueAsString == "Choice1") {

this.getField("A").readonly = false;

this.getField("B").readonly = false;

this.getField("C").readonly = false;

} else {

this.getField("A").readonly = true;

this.getField("B").readonly = true;

this.getField("C").readonly = true;

}

 

 

 

  • And in "myCheckBox" with export value of "Choice2" I used this: 

 

 

this.getField("A").readonly = true;
this.resetForm(["A"]);

this.getField("B").readonly = true;
this.resetForm(["B"]);

this.getField("C").readonly = true;
this.resetForm(["C"]);

 

 

View solution in original post

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

 

There many ways to do this with JavaScript scripting.

 

In my example below I named the checkboxes for yes and no with the same field name "myCheckBox" and then I set  them up each one  with a different export value for example: "Choice1", and "Choice2" respectively.

 

For the 3 checkboxes A, B, and C I created them and named them as shown in the scripts below and also set their field property to read-only (as default): 

 

  • in myCheckBox with export value of "Choice1" I used this script

 

 

if (event.target.valueAsString == "Choice1") {

this.getField("A").readonly = false;

this.getField("B").readonly = false;

this.getField("C").readonly = false;

} else {

this.getField("A").readonly = true;

this.getField("B").readonly = true;

this.getField("C").readonly = true;

}

 

 

 

  • And in "myCheckBox" with export value of "Choice2" I used this: 

 

 

this.getField("A").readonly = true;
this.resetForm(["A"]);

this.getField("B").readonly = true;
this.resetForm(["B"]);

this.getField("C").readonly = true;
this.resetForm(["C"]);

 

 

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

OMG, works perfectly!!!  So straight forward and elegant!  Thank you so much ❤️

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

You're welcome.

Votes

Translate

Translate

Report

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 ,
Sep 30, 2021 Sep 30, 2021

Copy link to clipboard

Copied

I can see how this work, but I cant figure out where you are putting it.

What triggering event are you using?

I have referneces to an ON CHANGE, but I cant seem to find anything like that.

See attachment

 

 

 

Votes

Translate

Translate

Report

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 ,
Sep 30, 2021 Sep 30, 2021

Copy link to clipboard

Copied

LATEST

Is a MouseUp event.

Votes

Translate

Translate

Report

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