Document Level Function Syntax

New Here ,
Apr 15, 2021 Apr 15, 2021

Copy link to clipboard

Copied

I have a number of places in my form where checkboxes make another field visible/hidden. I started coding each checkbox with a Mouse Up script:

 

var pop = this.getField("A1.Text.0")

if (event.target.value == "Yes") { // Is the check box selected?

pop.hidden = false // Yes: make the form fields visible

}

else { // No: Hide the form fields again

pop.hidden = true

}

 

However it seems clear that the most efficient approach would be a document level script that I can call wherever it is needed. I found this sample script that seems a little more efficient than mine and I'm trying to adapt it to document level:

 

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

this.getField("A1.Text.0").display = showHide

 

It seems like this should be written as a function rather than as a variable definition so I tried this:

 

function showHide(fieldPeek)

{

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

this.getField(fieldPeek).display = showHide

}

 

So then the Mouse Up event would be:

 

function showHide("A1.Text.0")

 

But I'm missing something and I'm not sure what.

TOPICS
How to, JavaScript, PDF forms

Views

34

Likes

translate

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

Adobe Community Professional , Apr 15, 2021 Apr 15, 2021
Try like this: function showHide(fieldPeek){this.getField(fieldPeek).display = event.target.isBoxChecked(0) ? display.visible : display.hidden;}

Likes

translate

Translate

Translate
Adobe Community Professional ,
Apr 15, 2021 Apr 15, 2021

Copy link to clipboard

Copied

Try like this:

function showHide(fieldPeek){
this.getField(fieldPeek).display = event.target.isBoxChecked(0) ? display.visible : display.hidden;}

Likes

translate

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
New Here ,
Apr 16, 2021 Apr 16, 2021

Copy link to clipboard

Copied

That worked perfectly!! How would I write it to toggle read only for a field? This didn't work:

 

function onOff(fieldRead){
this.getField(fieldRead).readonly = event.target.isBoxChecked(0) ? readonly.false : readonly.true;}

Likes

translate

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
Adobe Community Professional ,
Apr 16, 2021 Apr 16, 2021

Copy link to clipboard

Copied

No need to use readonly.false...etc false/true is enough, like this

? false : true;}

 

Likes

translate

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