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

Make a text Field appear/disappear biased on another text fields value

New Here ,
Feb 17, 2020 Feb 17, 2020

Copy link to clipboard

Copied

I am trying to get a text field to disappear if the value in a different text field is equal to or greater than 21.  specifically one text field is titled (”MASTER: age”) another text field is (”under 21 instructions”) the third is (”over 21 instructions”).   (”MASTER: age”)  is automatically calculated based off the date of birth entered in a separate text field.  

 

If (”MASTER: age”)is 21 or older I want (”under 21 instructions”)to disappear & (”over 21 instructions”) to appear. 

 

If (”MASTER: age”)is 21 or older I want (”under 21 instructions”)to appear & (”over 21 instructions”) to disappear.  

What text field should I attach the code to, and what code is needed. Everything I've tried so far has not worked.

TOPICS
Create PDFs , General troubleshooting , How to , PDF forms

Views

1.0K

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

Hi,

 

See here: https://stackoverflow.com/questions/36959629/adobe-pdf-javascript-for-forms-showing-hiding-labels-depending-on-the-conditi 

 

You can try something like this (it worked on my end):

 

//Place this code on the Custom Format Script of the "MASTER: age" field


var master = this.getField("MASTER: age").value;

if (master == "")
{
    getField("under 21 instructions").display=display.hidden;
    getField("over 21 instructions").display=display.hidden;

}
else if (master >= 21)
{

    getFie
...

Votes

Translate

Translate
Community Expert ,
Feb 18, 2020 Feb 18, 2020

Copy link to clipboard

Copied

Hi,

 

See here: https://stackoverflow.com/questions/36959629/adobe-pdf-javascript-for-forms-showing-hiding-labels-de... 

 

You can try something like this (it worked on my end):

 

//Place this code on the Custom Format Script of the "MASTER: age" field


var master = this.getField("MASTER: age").value;

if (master == "")
{
    getField("under 21 instructions").display=display.hidden;
    getField("over 21 instructions").display=display.hidden;

}
else if (master >= 21)
{

    getField("under 21 instructions").display=display.hidden;
    getField("over 21 instructions").display=display.visible;

}
else if (master <= 20)
{   
    getField("under 21 instructions").display=display.visible;
    getField("over 21 instructions").display=display.hidden;

}


 

 

Place the in the "MASTER: age" field custom format script as shown in the slide below:

 

hiddenfields.png

 

 

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
New Here ,
Feb 18, 2020 Feb 18, 2020

Copy link to clipboard

Copied

Worked like a charm, thank you for the 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
Community Expert ,
Feb 18, 2020 Feb 18, 2020

Copy link to clipboard

Copied

You're welcome.

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

Copy link to clipboard

Copied

Here's an article on exactly this topic:

https://acrobatusers.com/tutorials/show_hide_fields/

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 ,
Jan 04, 2023 Jan 04, 2023

Copy link to clipboard

Copied

Hi There:

I am trying to do something similar to the above. I set up a javascript based on this thread but I have a sytax error on line 10 and cannot for the life of me figure out what I have done wrong. The file is set up so that when a user types in one of three different dividend rates, the correct Annual Percentage field will appear. It's probably something really stupid since I don't do this very often. I am attaching the plain text file I have made.

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 ,
Jan 04, 2023 Jan 04, 2023

Copy link to clipboard

Copied

Next time please use the code box to post your code.  

 

One error is that "%" is not a valid character for a number. remove it.

Another error in the code (but isn't something that would be reported) is that the "=" character is for assigning a value. Use "==" for comparisons.  

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 ,
Jan 05, 2023 Jan 05, 2023

Copy link to clipboard

Copied

Thanks so much Thom.

I realized I did not have some field names correct, so I did that and this is now my code (the correct name of the field I am trying to add this to is "Dividend Rate"--Problem being that there is a sytanx error in line 3 or 4, but I can't figure it out. Can you please help me out again?

var master = this.getField("Dividend Rate").value;

if (Dividend Rate = "")
{
    getField("APY-TW").display=display.hidden;
    getField("APY-TWP").display=display.hidden;
    getField("APY-TFA").display=display.hidden;

}
else if (Dividend Rate = 3.920)
{

    getField("APY-TW").display=display.visible;
    getField("APY-TWP").display=display.hidden;
    getField("APY-TFA").display=display.hidden;

}
else if (Dividend Rate = 4.400)
{   
    getField("APY-TW").display=display.hidden;
    getField("APY-TWP").display=display.visible;
    getField("APY-TFA").display=display.hidden;

}
else if (Dividend Rate = 4.880)
{   
    getField("APY-TW").display=display.hidden;
    getField("APY-TWP").display=display.hidden;
    getField("APY-TFA").display=display.visible;

}

 

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 ,
Jan 05, 2023 Jan 05, 2023

Copy link to clipboard

Copied

LATEST

Again, the "=" character is for assignment, not comparison. 

But the error is on the line

if (Dividend Rate = "")

 

Dividend Rate is not a legal name for a variable, because it contains a space.  But I think you meant to use the variable you defined in the first line that is assigned the value of the "Dividend Rate" field. 

 

The line should be this.

if (master == "")

 

Also, always prefix getField() with the this keyword. 

 this.getField("...")

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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