These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Add Button field with script attached

srprice
Registered: Sep 19 2007
Posts: 138
Answered

I'm trying to programmatically add a button with some Javascript code. This button when click should go to a specific page. Simple right? For some reason I can't get it to work. I know it is something simple I'm missing but it just won't work. I'm not getting any error messages. The button is there but it doesn't execute the code.

Can someone please help?

Code:

var btn = this.addField("link","button",0, [140, 685, 470, 665]);
btn.setAction = ("MouseUp", "this.pageNum=7;");
btn.delay = true;
btn.highlight = "push";
btn.fillColor = color.transparent;
btn.delay = false;

Thanks,

scopley

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
The value for the 'highlight" property is not one of the vaild options listed in the Acrobat JS API Reference.

George Kaiser

srprice
Registered: Sep 19 2007
Posts: 138
I took the highlight property out but it still does not work.

I got that from the Javascript API Version 8.1 under the setActions function. But I have found other typos in there.

scopley
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
The table from the "highlight" field properties:

Type Keyword
none highlight.n
invert highlight.i
push highlight.p
outline highlight.o

George Kaiser

srprice
Registered: Sep 19 2007
Posts: 138
Thanks for the info. I found it in the API and changed the code

btn.highlight = highlight.p;

but still got the same result.

scopley
try67
Expert
Registered: Oct 30 2008
Posts: 2398
The problem is not with your highlight setting ("push" is a valid option), but with your coordinates. It places the button outside of the border of a standard page (which I assume is what you're using). Also making the button transparent doesn't help...

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
The following code does work:
var btn=this.addField("link","button",0,[140,685,470,665]);btn.setAction("MouseUp","this.pageNum=7;");btn.delay=true;btn.highlight='push';btn.fillColor=color.transparent;btn.delay=false;

You do not use a set operator, '=', with the 'setAction' method.

George Kaiser

srprice
Registered: Sep 19 2007
Posts: 138
It was the = sign that did it. Thank you very much.

scopley