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

hide and show image fields based on value

Participant ,
Nov 09, 2020 Nov 09, 2020

Copy link to clipboard

Copied

I have two image fields and images are read only. I have a text field and I want to swop images based on values. If the value is 0 or less than 0 like - 1 image1 and if +1 or greater than +1 then image2.

 

Is this possible?

TOPICS
PDF forms

Views

805

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 , Nov 09, 2020 Nov 09, 2020

Sure. As the custom validation script of the text field enter the following:

this.getField("image1").display = (event.value<=0) ? display.visible : display.hidden;

this.getField("image2").display = (event.value>0) ? display.visible : display.hidden;

Votes

Translate

Translate
Community Expert ,
Nov 09, 2020 Nov 09, 2020

Copy link to clipboard

Copied

Sure. As the custom validation script of the text field enter the following:

this.getField("image1").display = (event.value<=0) ? display.visible : display.hidden;

this.getField("image2").display = (event.value>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 Expert ,
Nov 09, 2020 Nov 09, 2020

Copy link to clipboard

Copied

You can read all about Hide/Show scripts here:

https://www.pdfscripting.com/public/Hiding-and-Showing-Form-Fields.cfm?sd=40

 

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
Participant ,
Nov 09, 2020 Nov 09, 2020

Copy link to clipboard

Copied

Really magic. Just one more question. If the value is 0 then both images should be hidden. Can you please modify code?

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 ,
Nov 09, 2020 Nov 09, 2020

Copy link to clipboard

Copied

You can see that the condition on the first line of code is   event.value<=0  . This is read as "when the value is less than or equal to 0" .  When the codition is satisfied the display setting for the field is set to display.visible .  I think you can see how this works. If you want both images to be hidden, then the condition needs to be modified so that it is not true when the value is 0, i.e., remove the equals.

 

 

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
Participant ,
Nov 10, 2020 Nov 10, 2020

Copy link to clipboard

Copied

LATEST

So kind of you. Thank you!

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