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

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

New Here ,
Jan 28, 2016 Jan 28, 2016

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!

TOPICS
Acrobat SDK and JavaScript
836
Translate
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

correct answers 1 Correct answer

Community Expert , Jan 30, 2016 Jan 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

...
Translate
Community Expert ,
Jan 30, 2016 Jan 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.

Translate
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 ,
Feb 01, 2016 Feb 01, 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.

Translate
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 ,
Feb 01, 2016 Feb 01, 2016

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

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

Translate
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 ,
Feb 01, 2016 Feb 01, 2016
LATEST

Thanks a bunch try67!

I was able to get this to work the way I wanted it to thanks to your help. I had to experiment a bit to get the checkbox1 to toggle. I wound up using the code below...

//Script to check the box and display a date if number is greater than zero

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

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

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

} else { 

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

}

// script below to uncheck the box if value is zero

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

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

}

Translate
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