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

what script to use to automatically tick checkbox if 1 of 2 conditions are met?

Community Beginner ,
Sep 08, 2018 Sep 08, 2018

Copy link to clipboard

Copied

Variable 1 = text field

variable 2 = checkbox 1

variable 3 = checkbox 2

Condition:

if variable 1 is completed, tick checkbox 2 and hide checkbox 1

if checkbox 1 is tick, tick checkbox 2 and text field is hidden

Either variable 1 or variable 2 is required to tick checkbox 2.

What script should I use?

Thanks a lot!

TOPICS
Acrobat SDK and JavaScript

Views

828

Translate

Translate

Report

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 , Sep 08, 2018 Sep 08, 2018

Change the checkbox1 MouseUp script to this.

var showHide = event.target.isBoxChecked(0)?display.hidden:display.visible;

this.getField("textfield").display = showHide;

this.getField("Checkbox2").value = event.target.value;

This will fix the issue with checkbox 2 not turning off. Also, the first two lines are repeats, so I removed one of them.

Votes

Translate

Translate
LEGEND ,
Sep 08, 2018 Sep 08, 2018

Copy link to clipboard

Copied

What is the condition that causes Variable one considered to be completed?

How does one know if the fields are required or not?

Are the fields always required?

What happens to the text field's value when check box 1 has been selected?

Can the user change checkbox 2?

Votes

Translate

Translate

Report

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 ,
Sep 08, 2018 Sep 08, 2018

Copy link to clipboard

Copied

Since this is a complicated operation you need to create a table that shows all options and responses so that there aren't any situations that will cause an issue.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

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 Beginner ,
Sep 08, 2018 Sep 08, 2018

Copy link to clipboard

Copied

Hi,

Somehow, I was able to make it work except, when you uncheck "Checkbox1", "Checkbox2" still remains checked.  I think there's a missing script somewhere.  Here's my script on Checkbox 1:

var showHide = event.target.isBoxChecked(0)?display.hidden:display.visible;

this.getField("textfield").display = showHide;

var showHide = event.target.isBoxChecked(0)?display.hidden:display.visible;

this.getField("textfield").display = showHide;

//other action

if (this.getField("Checkbox1").value!="On"){

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

}

It does what I need, i.e., when checkbox 1 is checked it hid the text field and checkbox 2 is also checked.  But if I uncheck checkbox 1, it shows the textfield which is what I need but checkbox 2 remains checked.  What I want to happen is when I uncheck checkbox 1, checkbox 2 will also uncheck.

I also added a custom format script to the textfield which does what I need, i.e., if I type something in the textfield, checkbox 2 is checked.  It does not hide checkbox 1 though.

this.getField("checkbox2").checkThisBox(0,!/^\s*$/.test(event.value));

checkbox2  needs to be "required" so I set it as required in the common properties.

Hope this make sense.

Votes

Translate

Translate

Report

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 ,
Sep 08, 2018 Sep 08, 2018

Copy link to clipboard

Copied

Change the checkbox1 MouseUp script to this.

var showHide = event.target.isBoxChecked(0)?display.hidden:display.visible;

this.getField("textfield").display = showHide;

this.getField("Checkbox2").value = event.target.value;

This will fix the issue with checkbox 2 not turning off. Also, the first two lines are repeats, so I removed one of them.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

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 Beginner ,
Sep 08, 2018 Sep 08, 2018

Copy link to clipboard

Copied

LATEST

This works!  Thanks a lot Thom.

Votes

Translate

Translate

Report

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