Skip to main content
CheDee317
Known Participant
September 8, 2018
解決済み

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

  • September 8, 2018
  • 返信数 3.
  • 1071 ビュー

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!

このトピックへの返信は締め切られました。
解決に役立った回答 Thom Parker

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.

返信数 3

CheDee317
CheDee317作成者
Known Participant
September 8, 2018

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.

Thom Parker
Community Expert
Thom ParkerCommunity Expert解決!
Community Expert
September 9, 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.

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
CheDee317
CheDee317作成者
Known Participant
September 9, 2018

This works!  Thanks a lot Thom.

Thom Parker
Community Expert
Community Expert
September 8, 2018

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 PDFScriptingUse the Acrobat JavaScript Reference early and often
Inspiring
September 8, 2018

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?