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

Show or hide image fields based on text value in another field

Engaged ,
Dec 20, 2021 Dec 20, 2021

Hi all,

 

Have an issue with attempting to get image fields to either become visible, or hidden - depending on the 3-letter text value that is entered in a field.

 

I have the fields name as follows;

 

"Leg1" - text in 3-letter format is entered here, e.g. "ERF", "PAD", "BCN" & "STN".

"Fuellleg1_1" - dsiplays an icon only

"Fuellleg1_2" - dsiplays an icon only

"Fuellleg1_3" - dsiplays an icon only

 

If the text of either/or "ERF", or "PAD" is entered in to the "Leg1" field, then the "Fuellleg1_1" field shoud be displayed in either/or case, and the "Fuellleg1_2" and "Fuellleg1_3" fields should be hidden.

 

If the text  "BCN" is entered in to the "Leg1" field, then the "Fuellleg1_2" field should be displayed, and the "Fuellleg1_1" and "Fuellleg1_3" fields should be hidden.

 

If the text  "STN" is entered in to the "Leg1" field, then the "Fuellleg1_3" field should be displayed, and the "Fuellleg1_1" and "Fuellleg1_2" fields should be hidden.

 

If there is no text , e.g. " " is entered in to the "Leg1" field, then the "Fuellleg1_1", "Fuellleg1_2" and "Fuellleg1_3" fields (i.e. all of the fields) should be hidden.

 

Any ideas? I've tried alas in various ways but to no effect....

TOPICS
PDF forms
2.7K
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 ,
Dec 20, 2021 Dec 20, 2021

As Bernd suggests, a validation script on the "Leg1" field is a good choice.

For example:

switch(event.value)
{
    case "PAD":
    case "ERF":
       this.getField("Fuellleg1_1").display = display.visible;
       this.getField("Fuellleg1_2").display = display.hidden;
       this.getField("Fuellleg1_3").display = display.hidden;
       break;
    case "BCN":
       this.getField("Fuellleg1_1").display = display.hidden;
       this.getField("Fuellleg1_2").display = display.visible;
       this.getField("Fuellleg1_3").display = display.hidden;
       break;
    case "STN":
       this.getField("Fuellleg1_1").display = display.hidden;
       this.getField("Fuellleg1_2").display = display.hidden;
       this.getField("Fuellleg1_3").display = display.visible;
       break;
    default:
       this.getField("Fuellleg1_1").display = display.hidden;
       this.getField("Fuellleg1_2").display = display.hidden;
       this.getField("Fuellleg1_3").display = display.hidden;
       break;
}
Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 ,
Dec 20, 2021 Dec 20, 2021

You can use a validation script at field "Leg1".

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 ,
Dec 20, 2021 Dec 20, 2021

As Bernd suggests, a validation script on the "Leg1" field is a good choice.

For example:

switch(event.value)
{
    case "PAD":
    case "ERF":
       this.getField("Fuellleg1_1").display = display.visible;
       this.getField("Fuellleg1_2").display = display.hidden;
       this.getField("Fuellleg1_3").display = display.hidden;
       break;
    case "BCN":
       this.getField("Fuellleg1_1").display = display.hidden;
       this.getField("Fuellleg1_2").display = display.visible;
       this.getField("Fuellleg1_3").display = display.hidden;
       break;
    case "STN":
       this.getField("Fuellleg1_1").display = display.hidden;
       this.getField("Fuellleg1_2").display = display.hidden;
       this.getField("Fuellleg1_3").display = display.visible;
       break;
    default:
       this.getField("Fuellleg1_1").display = display.hidden;
       this.getField("Fuellleg1_2").display = display.hidden;
       this.getField("Fuellleg1_3").display = display.hidden;
       break;
}
Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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
Engaged ,
Dec 20, 2021 Dec 20, 2021

Thom/Bernd,

 

Thanks so much - I would never have been able to come up with that, beautiful! really appreciated, many thanks.

 

😉

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
Engaged ,
Mar 12, 2022 Mar 12, 2022

While I realize this post is several months old, I recently tried this validation script based on a selection in a combo box where each item has been assigned an export value. As I thought the event.value was assigned an export value different from the text item selected, for whatever reason the validation script doesn't appear to work. However, if I then delete all the export values and use the selected item string name, it works without flaw. Am I missing something here? On another note, it sure would be beneficial if a combo or list box were designed to allow adding an image next to a text item. While the validation script provided is the next best thing to not having this feature, unfortunately, the image doesn't display until the field loses focus. While I have as yet to investigate the possibility, I am wondering if there is a way to create a popup menu to display text alongside an image?

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 ,
Mar 12, 2022 Mar 12, 2022

Set your combox to "Commit selected item immediately". You'll find this option on the Options tab on the Properties dialog for the combo box field.

 

https://www.pdfscripting.com/public/Editing-Fields-Properties.cfm

 

 

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

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
Engaged ,
Mar 13, 2022 Mar 13, 2022

Thanks Tom. I've been away from Acrobat for some years so I am admittedly a little bit rusty. Always know I can count on your expertise when it comes to Questions related to Acrobat. On another note, I had saved an article you authored many years ago on using the popup menu. Not to flatter you but it has to be one of the best if not the best article explaining how to create and implement a popup menu using Javascript. Needless to say, I learned a lot from reading that article the apples, oranges, etc., example comes to mind where I was thinking how amazing it would be if there were some way to create and add the images next to the text. In reality, I am really kind of surprised and disappointed Adobe never came up with a combo box to include such a feature. Your thoughts.

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 ,
Mar 17, 2022 Mar 17, 2022

There are many things about PDF form fields that could be massively improved. The same thing could be said about the JavaScript model. The two are related. But there are reasons. PDF forms were added many years ago. Expectations were different then. PDF is supposed to be like static paper, not like a dynamic web page.  PDF is an ISO spec, so what's defined now takes an act of god to change. 

 

 

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

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
New Here ,
May 11, 2024 May 11, 2024

Screenshot_20240512_024215.jpgexpand image

 

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
New Here ,
May 11, 2024 May 11, 2024
LATEST

IMG_20240512_072848_355.jpgexpand image

 

Football 
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