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, How to, PDF forms

Views

279

Likes

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

Most Valuable Participant , 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.

Likes

Translate

Translate
Most Valuable Participant ,
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?

Likes

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. 

Likes

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
Most Valuable Participant ,
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.

Likes

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. 

Likes

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
Most Valuable Participant ,
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.

Likes

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. 

Likes

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
Most Valuable Participant ,
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

Likes

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 ! 

Likes

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