How to Hide Text in PDF Based on Combo Box Selection
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
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.
Use the Acrobat JavaScript Reference early and often

