Showing a field based on layer visibility

New Here ,
Apr 27, 2022 Apr 27, 2022

Copy link to clipboard

Copied

I am setting up mouseup javascript for a checkbox which shows or hides a couple buttons (Yes and No) based on whether a specific layer is visible. It is layer 0 in the document (I think? It's the first layer I added), the doc is only one page long. I have tried many different ways based on what I've cobbled together from searching online but nothing works. Can anyone tell me if I'm on the right track/advise? Thanks!

 

if ( event.target.isBoxChecked(0)) {
    this.getField("Yes").display = display.hidden;
    this.getField("No").display = display.hidden;
   } else if (this.getOCGs((0).layers[0]).state == "true")
{
    this.getField("Yes").display = display.visible;
    this.getField("No").display = display.visible;
} else {
    this.getField("Yes").display= display.hidden;
    this.getField("No").display = display.hidden;
}

 

TOPICS
JavaScript , PDF forms

Views

54

Likes

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
Adobe Community Professional ,
Apr 27, 2022 Apr 27, 2022

Copy link to clipboard

Copied

Check the Javascript console for errors.

Likes

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
Adobe Community Professional ,
Apr 28, 2022 Apr 28, 2022

Copy link to clipboard

Copied

LATEST

This is incorrect:

if (this.getOCGs((0).layers[0]).state == "true")

Change it to:

if (this.getOCGs()[0].state == true)

 

PS. It's not a good idea to refer to layers by their index number, as their location in the OCGs array can change.

You should iterate over the array, checking the name of each item in it, until you find the one you're looking for.

Likes

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