Highlighted

Set Destination When Creating Automated Button

Community Beginner ,
Aug 21, 2020

Copy link to clipboard

Copied

I've been using buttons to create custom buttons throughout my PDF. Is it possible to set a destination in the javascript or does that have to be manual?

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

Change this line:

newButton.setAction("MouseUp", "this.getField("BACK-A" + aCount).setFocus();")"
To:

newButton.setAction("MouseUp", "this.getField(\"BACK-A" + aCount + "\").setFocus();")"

Topics

Create PDFs, How to, PDF forms, Standards and accessibility

Views

69

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

Set Destination When Creating Automated Button

Community Beginner ,
Aug 21, 2020

Copy link to clipboard

Copied

I've been using buttons to create custom buttons throughout my PDF. Is it possible to set a destination in the javascript or does that have to be manual?

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

Change this line:

newButton.setAction("MouseUp", "this.getField("BACK-A" + aCount).setFocus();")"
To:

newButton.setAction("MouseUp", "this.getField(\"BACK-A" + aCount + "\").setFocus();")"

Topics

Create PDFs, How to, PDF forms, Standards and accessibility

Views

70

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
Aug 21, 2020 0
Most Valuable Participant ,
Aug 21, 2020

Copy link to clipboard

Copied

JavaScript can only apply JS-based actions to a button. A script can be used to make the document switch to a specific page, or even to a specific page view, or a Named Destination, though. What exactly do you want to happen when the button is clicked?

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
Reply
Loading...
Aug 21, 2020 0
Community Beginner ,
Aug 24, 2020

Copy link to clipboard

Copied

I'm using a single button that creates other buttons on click. I'd like those buttons to have a destination attached to them, so wherever I place them in the document, they can be navigated to. I see that I need to keep recalibrating my destination buttons every time more information created within my PDF. Could I use Javascript to create destinations? 

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
Reply
Loading...
Aug 24, 2020 0
Most Valuable Participant ,
Aug 24, 2020

Copy link to clipboard

Copied

No. However, you can jump to a button's location, even if it's not always the same, like this:

this.pageNum = this.getField("Button1").page;

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
Reply
Loading...
Aug 24, 2020 0
Community Beginner ,
Aug 24, 2020

Copy link to clipboard

Copied

I'll try that out for sure! Thanks for the help!

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
Reply
Loading...
Aug 24, 2020 0
Most Valuable Participant ,
Aug 24, 2020

Copy link to clipboard

Copied

Another option is to use the setFocus command, which will cause the cursor to "jump" to the field, and to the page to change to where it's located:

 

this.getField("Button1").setFocus();

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
Reply
Loading...
Aug 24, 2020 0
Community Beginner ,
Aug 24, 2020

Copy link to clipboard

Copied

 

 

I've been trying to use the setFocus method dynamically by assigning it to a "setAction." I placed in my new button and each time I try it fails to work. 

 

 Below is where I want setFocus, a new button would be able to navigate to a reference button called (i.e. "BACK-A1, A2, A3, etc.")

 

Is focus only used once throughout the document? I would love to assign each button to its own unique "focus point."

 

 function CreateField(){

     var newButton = this.addField("newButton" + aCount, "button", this.pageNum, [0, 20, 80, 0]);

     aCount++

     newButton.buttonSetCaption("FINDING" + " A-" + aCount);

    ** Below is the issue **

     newButton.setAction("MouseUp", "this.getField("BACK-A" + aCount).setFocus();")"

     return newButton;

}

CreateField();

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
Reply
Loading...
Aug 24, 2020 0
Most Valuable Participant ,
Aug 24, 2020

Copy link to clipboard

Copied

I'd expect to see plenty of errors in the JavaScript log from this code. Do you see any?

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
Reply
Loading...
Aug 24, 2020 0
Most Valuable Participant ,
Aug 24, 2020

Copy link to clipboard

Copied

Change this line:

newButton.setAction("MouseUp", "this.getField("BACK-A" + aCount).setFocus();")"
To:

newButton.setAction("MouseUp", "this.getField(\"BACK-A" + aCount + "\").setFocus();")"

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
Reply
Loading...
Aug 24, 2020 0
A.J.5EA8 LATEST
Community Beginner ,
Aug 24, 2020

Copy link to clipboard

Copied

That worked perfectly. Thank you! I always forget the "\".

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
Reply
Loading...
Aug 24, 2020 0