Skip to main content
Participant
December 12, 2020
Answered

Checkbox behavior enables or disables other checkboxes

  • December 12, 2020
  • 1 reply
  • 7069 views

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!

This topic has been closed for replies.
Correct answer ls_rbls

 

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"]);

 

 

1 reply

ls_rbls
Community Expert
ls_rblsCommunity ExpertCorrect answer
Community Expert
December 13, 2020

 

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"]);

 

 

Participating Frequently
September 30, 2021

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

 

 

 

ls_rbls
Community Expert
Community Expert
October 1, 2021

Is a MouseUp event.