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

Making a field hidden or visible based on check box series

Explorer ,
Feb 24, 2020 Feb 24, 2020

Copy link to clipboard

Copied

Hi,

 

How can I make a text field visible based on a check box selection ? I tried the following: 

if (this.getField("MyCheckBox").isBoxChecked(0))
{this.getField("TextFormFieldToBeDisplayed").display = display.visible;}
else
{this.getField("TextFormFieldToBeDisplayed").display = display.hidden;}

But my check box is apart of a series .. I have 2 check boxes all called "template"

and their export values are individual, and multiple.

 

I am trying to make 1 text box visible and another one hidden if individual is selected, then reversed if multiple is selected.

 

Thank you!

TOPICS
Acrobat SDK and JavaScript

Views

1.4K

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 , Feb 25, 2020 Feb 25, 2020

Use a separate (hidden) text field with the following code as the custom calculation script:

 

var v = this.getField("MyCheckBox").valueAsString;
if (v=="Off" || v=="individual") {
	this.getField("Field1").display = display.visible;
	this.getField("Field2").display = display.hidden;
} else {
	this.getField("Field1").display = display.hidden;
	this.getField("Field2").display = display.visible;
}

 

Change the field names as needed, of course.

Votes

Translate

Translate
Community Expert ,
Feb 24, 2020 Feb 24, 2020

Copy link to clipboard

Copied

What about if neither one is selected? Also, where did you place this code?

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
Explorer ,
Feb 25, 2020 Feb 25, 2020

Copy link to clipboard

Copied

One always has to be selected for the siuation. Either one or the other is hidden. The question on the form is mandatory. 

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 ,
Feb 25, 2020 Feb 25, 2020

Copy link to clipboard

Copied

That doesn't mean it will always be the case. The user will be able to un-select both fields, and the script has to take that into consideration or you will get strange and probably unwanted results.

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
Explorer ,
Feb 25, 2020 Feb 25, 2020

Copy link to clipboard

Copied

If neither is selected then I would like the text box realted in "individual" to be visible and "multiple" hidden.

I pasted this code into the custom calculate of the text boxes. 

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 ,
Feb 25, 2020 Feb 25, 2020

Copy link to clipboard

Copied

Use a separate (hidden) text field with the following code as the custom calculation script:

 

var v = this.getField("MyCheckBox").valueAsString;
if (v=="Off" || v=="individual") {
	this.getField("Field1").display = display.visible;
	this.getField("Field2").display = display.hidden;
} else {
	this.getField("Field1").display = display.hidden;
	this.getField("Field2").display = display.visible;
}

 

Change the field names as needed, of course.

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
Explorer ,
Feb 25, 2020 Feb 25, 2020

Copy link to clipboard

Copied

Thank you! 

I have a dumb question .... how can I learn all of this?

Should I take coding classes or is there a better way to learn javascript for Adobe. 

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 ,
Feb 25, 2020 Feb 25, 2020

Copy link to clipboard

Copied

It's a pretty niche market, so there's not a huge amount of resources out there. It would be good to know some general coding practices and concepts, sure. On top of that you could use these resources:

General JS tutorial (note that only the core syntax applies to Acrobat): http://www.w3schools.com/js/default.asp
Homepage for Acrobat JavaScript development, including a link to the full API: http://www.adobe.com/devnet/acrobat.html
Free tutorials about Acrobat in general, including many JS related ones: https://acrobatusers.com/tutorials/
A paid-for website with tutorials about Acrobat JavaScript (not related to me): http://www.pdfscripting.com/
My humble web-site with many tools for Acrobat (mostly paid-for, some free): http://try67.blogspot.com

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
Explorer ,
Feb 25, 2020 Feb 25, 2020

Copy link to clipboard

Copied

LATEST

Thank you for all your help ! 

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