Skip to main content
TelcoCook
Participating Frequently
January 28, 2016
Answered

How can I activate a checkbox if data has been entered in a different text field?

  • January 28, 2016
  • 1 reply
  • 910 views

Hello. I would like to use four check boxes in a form, each of which will activate (check) if data has been entered into four separate form text fields on a different page in the same form.

Example:

Page 1 will have a question such as... How many apples did you eat last month? "text1" = 3

So, since the user answered 3 in form "text1" field, "checkbox1" should now be checked on page 2.

... and so on for the other three.

Note: The answers to the questions will all be as a number. If the user enters 0 (zero) then I do not want the check boxes to activate. So any answer greater than zero will check the checkbox.

Follow up question...

Is it possible for an entirely different form text field to be visible or not visible (with default read only text) based on the status of each checkbox mentioned above?

Example:

"checkbox1" will have a text field next to it named "date1"  with a hidden date. If "checkbox1" is checked (due to the actions above) then the date will be visible.

... and so on for the other three.

Thank you so much!

This topic has been closed for replies.
Correct answer try67

- You can use something like this as the custom validation script of your text field:

if (event.value=="3") this.getField("checkbox1").checkThisBox(0, true);

- Yes, but you shouldn't make it dependent on the check-box, but incorporate it into the script above, like this:

if (event.value=="3") {

    this.getField("checkbox1").checkThisBox(0, true);

    this.getField("date1").display = display.visible;

} else {

    this.getField("date1").display = display.hidden;

}

If you also want to un-check the check-box in case the value of the text field is not 3 then duplicate line #2 but with false instead of true in the else-block.

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
January 30, 2016

- You can use something like this as the custom validation script of your text field:

if (event.value=="3") this.getField("checkbox1").checkThisBox(0, true);

- Yes, but you shouldn't make it dependent on the check-box, but incorporate it into the script above, like this:

if (event.value=="3") {

    this.getField("checkbox1").checkThisBox(0, true);

    this.getField("date1").display = display.visible;

} else {

    this.getField("date1").display = display.hidden;

}

If you also want to un-check the check-box in case the value of the text field is not 3 then duplicate line #2 but with false instead of true in the else-block.

TelcoCook
TelcoCookAuthor
Participating Frequently
February 1, 2016

Thank you for the reply try67! I will work with this code tonight. What if the answer was any number greater than zero? Can I change the code to read ">0" instead of "3"?

Thank you.

try67
Community Expert
Community Expert
February 1, 2016

Yes, but then you need to make sure it's an actual number, so it should be:

if (Number(event.value)>0) {