
In this example a Square Markup Annotation is used.

For example, it could be an OCG, a Text Field, or a Stamp Annotation. There are several different ways to create this effect depending on the form developer’s skill level and tools available. The script for the Married Radio Button assigns display.visible to each of the fields in the Spouse Information block, and the script for the Single Radio Button assigns display.visible to these same fields.Īs well as the fields and field labels, the Spouse Information block includes a gray background that contains and highlights the Spouse Information fields. Each button has a script in the Mouse Up event.
#Javascript visibility code
Since it is a given when the user clicks on a button that button will be selected, there is no need for code to determine the state of the selection. In this sample there are two Radio Buttons, one hides the fields and one shows the fields. This characteristic simplifies the code for showing and hiding fields in Sample #2. The buttons are turned off automatically when the user makes another selection. One characteristic of Radio Buttons is that the user can only turn a button on. Setting Field Visibility based on a Radio Button Setting The additional lines of code simply apply the visibility state to the appropriate fields. This operator is equivalent to using an if statement. The true/false return value of this function is then used to select the visibility state with the Conditional Operator, i.e., the question mark operator. If there were several Check Boxes with the same name this argument would be used to distinguish between them. The argument to the function isBoxChecked() is a 0, which refers to the first instance of the checkbox. The first part of this code, event.target, refers to the target of the event, which is the Check Box.

The first line determines the visibility by examining the state of the check box with the (0) function. This.getField("ShippingStreet").display = nHide This.getField("LblShippingStreet").display = nHide This.getField("LblShippingInfo").display = nHide var nHide = (0)?display.visible:display.hidden The Mouse Down event would not work because it happens before the Check Box value is changed. This particular event is used because it happens after the value of the Check Box has been updated. The easiest approach is to use the Mouse Up event for the Check Box. For this sample, multiple fields receive the change, but only a single field (the Check Box) is used as the trigger. Which location is best depends on the specific situation. In general, there are two locations where the visibility code can be placed in the field that triggers the visibility change or the field that receives the visibility change. The field labels are really read-only text fields. Notice that not only are the entry fields made visible, but visibility of the field labels is also controlled. In the first example of the sample file a check box is used to display a set of fields for entering additional info. When checked, some other fields are made visible and when unchecked the fields are hidden. Probably the simplest case for setting field visibility is a single check box. Display constantsĪcrobat provides a set of constants in the display object so you don’t have to remember which integer value corresponds to which field display option.Īll examples are provided in Sample_ShowHideFields.pdfĭownload Setting Field Visibility based on a Single Check Box Setting Basically, always use the display property. Otherwise, stick with the display property. These properties are intended to be used only for scripts that will be viewed in the version of Acrobat preceding deprecation, which happens to be version 3.0. However, lots of documents had already been created using these properties so they left them in the DOM until such time they feel it’s ok to remove them in a future version. This means that Adobe re-thought how they had set up these properties and decided to change it. 3 Field Hidden in Viewer, Visible on Printed DocumentĪs noted in the table, the first two properties are deprecated.2 Field Visible in Viewer, Hidden on Printed Document.

