Skip to main content
Known Participant
July 19, 2022
Answered

Checkbox Toggle and Conditional Required Text Field

  • July 19, 2022
  • 1 reply
  • 2160 views

Hello,

I have a list of checkboxes (1-11) with Mouse Up script that unchecks Checkbox 12 if any of the checkboxes 1-11 are selected. If no checkboxes 1-11 are selected, then checkbox 12 is automatically checked. I have seen some refer to this as a toggle. See the following script:

var bChecked = (event.target.value == "Yes")

this.getField("Check Box12").value = bChecked?"Off":"Yes";

 

I have also set checkbox 12 as the default. So when a user opens the form, checkbox 12 will be checked unless they tick one of the boxes 1-11.

 

This works great, however, there is a text box that I would like to be required if checkbox 12 is checked. I believe the trouble I am having may be the result of the "toggle" function. Since there is no mouse function (up, down, enter, exit, on focus, or on blur) associated with the checking of box 12, I cannot seem to use script in the properties of the checkbox

 

Is there a custom calculation script that I can use for the text field to achieve my goal? Or any other options to make this possible? 

 

Thanks for any suggestions!

This topic has been closed for replies.
Correct answer Nesa Nurani

Yes, as custom calculation of that text field use this:

event.target.required = this.getField("checkbox 12").value == "Off" ? false : true;

1 reply

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
July 19, 2022

Yes, as custom calculation of that text field use this:

event.target.required = this.getField("checkbox 12").value == "Off" ? false : true;

Known Participant
July 19, 2022

Brilliant! Thanks!