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

Document Level Function Syntax

Community Beginner ,
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

553

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 , Apr 15, 2021 Apr 15, 2021

Try like this:

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

Votes

Translate

Translate
Community Expert ,
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;}

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 ,
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;}

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

Copy link to clipboard

Copied

LATEST

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

? false : true;}

 

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