Skip to main content
Participant
July 17, 2017
Answered

Is there a way to make a text field required if a check box is clicked?

  • July 17, 2017
  • 3 replies
  • 11966 views

I have a form I am trying to adjust. I want to make add a text field and make it required only if a check box above is checked. If the box is not checked no data is necessary in the field. Would someone tell me how to make this work? I'm a bit of a novice at coding but I have a resource who could likely help if we're pointed toward the process to make it work. Thanks!

-Nathanael

This topic has been closed for replies.
Correct answer try67

As the Mouse Up event of the check-box enter this code:

this.getField("Text1").required = event.target.value!="Off";

3 replies

cmvarga5
Known Participant
July 20, 2022

Can I also jump in on this thread with a question related to this?

 

How can we hide that required text field and make it visible when the check box is selected? Will the code provided work if we add another code after it?

Inspiring
November 7, 2020

I'm glad I found this post after searching for a couple of days, and have the following question:

If I have two text fields that I want to make a required entry, after a box is checked, do I just repeat the code with the new field name?

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
July 17, 2017

As the Mouse Up event of the check-box enter this code:

this.getField("Text1").required = event.target.value!="Off";

Participant
July 18, 2017

Awesome! That worked perfectly! Thank you!