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

Document Level Function Syntax

Community Beginner ,
Apr 15, 2021 Apr 15, 2021

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
868
Translate
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
1 ACCEPTED SOLUTION
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;}

View solution in original post

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

Try like this:

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

Translate
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

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

Translate
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
LATEST

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

? false : true;}

 

Translate
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