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

How to Hide Text in PDF Based on Combo Box Selection

Explorer ,
Nov 10, 2023 Nov 10, 2023

Hi Team,

 

I'm working on an interactive PDF form in Adobe Acrobat, and I have a combo box field named "Health_Plan." I want to hide a specific text element ("Sepatha® is available on:") when the user selects a visually blank list item in the combo box.

I found the below script in one reference file which is working same as my requiremnt.
I've tried using the JavaScript code below in the JavaScript Console of my document but its not working:

// -------------------------------------------------------------
// ----------------- Do not edit the XML tags -----------------
// -------------------------------------------------------------

// <AcroForm>
// <ACRO_source>Health_Plan:Validate</ACRO_source>
// <ACRO_script>
/*********** belongs to: AcroForm:Health_Plan:Validate ***********/

var layers = this.getOCGs();
var v = event.value;

for (var i = 0; i < layers.length; i++) {
if (layers[i].name === "Repatha_Is_Available_On") {
if (v === "") {
layers[i].state = false;
} else {
layers[i].state = true;
}
}
}

// </ACRO_script>
// </AcroForm>

However, I'm not sure if this is the correct approach or if there's a better way to achieve this behavior. Could someone please provide guidance on how to dynamically hide a specific text element based on the selection made in a combo box?

Any help or suggestions would be greatly appreciated. Thank you!


TOPICS
How to , JavaScript , PDF , PDF forms
1.1K
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 ,
Nov 10, 2023 Nov 10, 2023

If you don't need the entire page's layout to change the easiest way is to put the text in a read-only text field (as its default value) and then show/hide that field as needed. Or you can put a read-only button with a white fill color over the text and show the field when you want to hide the text, and vice versa.

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
Explorer ,
Nov 14, 2023 Nov 14, 2023

Hi  thankyou for your responce.

But the text frame should hide when the user click the Empty list item from the combo box list. how can i achive this.

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 ,
Nov 14, 2023 Nov 14, 2023
LATEST

How its done depends on where the text exists. From your post I suspect the text is page content. In this case the only way to hide and show it is to place something over the page text. Then hide/show this object. A good choice is to use a button field with no border and a background that matches the page background.  

Here's an article on how the hide/show a form field. 

https://www.pdfscripting.com/public/Hiding-and-Showing-Form-Fields.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
Community Expert ,
Nov 10, 2023 Nov 10, 2023

In order for that script to work the text on the page would need to be marked as an OCG.  To do this in Acrobat you would need to create the hidden text sections separately and import them as layers. 

 

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