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

Create Fields With JavaScript

slzamora
Registered: Jan 4 2008
Posts: 20

I have searched and read myself "blind" trying to find what must be a great secret: How do I create a field with JavaScript, specifically a combo box?

I've printed and read the old Acrobat 7 JavaScripting Guide and Reference, and now the Acrobat 9 Help located on the adobe.com site. I find all kinds of examples of code to create different types of fields. But I can't seem to find the instructions that tell me where to put the code.

My big question is: Where does the code go? I've tried unsuccessfully putting it in a function going through the Advanced, Document Processing, Document JavaScripts menu. Am I just missing "the forrest for the trees?"

My Product Information:
Acrobat Pro 9.0, Windows
try67
Expert
Registered: Oct 30 2008
Posts: 2398
To add a field you simply use the Document's method, addField. One of it's parameters specifies which type of field it is, as is mentioned in the reference files.
About where to put it: that depends on when you want it to execute. If you just want to test it out, or run it once, use the console. If you want it to be available at all times and for multiple files, place it in a folder level script, attached to a menu item. There are many options, depending on what you want to achieve.

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

slzamora
Registered: Jan 4 2008
Posts: 20
You've restated the Acrobat Help reference, "... simply use the Document's method, addField." and that doesn't help me because I don't understand the term "Document's method". I want to create a combo box field in a specific form available only to that form. The combo has approximately 25 options. I would like to just be able to edit JavaScript when those options have to be updated.

I looked at your web site. I cannot purchase any of your scripts as I work for a budget-strapped government entity. I am on my own finding a solution to what I want to do.

Thank you for your reply.
try67
Expert
Registered: Oct 30 2008
Posts: 2398
You're talking of two different things: Adding a field and setting the items of an existing combo-box.
Let me give you an example that might set you in the right path. So if you have a file open, open the console (Ctrl+J), and execute this code:
this.addField({cName:"ComboBox1", cFieldType:"combobox", nPageNum:0, oCoords:[0,792,80,742]});
This should place a new combo-box at the upper left-hand corner of the first page.

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

slzamora
Registered: Jan 4 2008
Posts: 20
I pasted your code into the Console, pressed Enter; no combo box on my pdf. Actually, I did this too after getting this same instruction from somewhere. I didn't get a combo box that time either.
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Did you press the Enter key at the bottom right-hand corner of the keyboard?

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

slzamora
Registered: Jan 4 2008
Posts: 20
No, I pressed the Enter key above Shift. I thought they were both the same command. I just did it your way and I see a combo box without any options!! :)
Now how do I give it options? Is the code going to reside in the Console forever? I thought it has to go into a function. ??
try67
Expert
Registered: Oct 30 2008
Posts: 2398
They usually are, but not in this context.
This code will be removed from the console when you close Acrobat. If you want it to always be accessible through a menu item you need a folder-level script.
Thom Parker's tutorial is a good place to start learning about it:
http://www.acrobatusers.com/tutorials/2006/folder_level_scripts

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

slzamora
Registered: Jan 4 2008
Posts: 20
I think I've already been through Thom's tutorials and actually found a solution to part of what I'm trying to achieve. I'll look again.

Can you recommend any reference books that teach JavaScripting in Acrobat, specifically for fillable forms? I looked at some books a couple weeks ago at the bookstore but they were all about JavaScripting for web pages. None of them showed me what I was looking for either.
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Almost everything you need to know is in the reference files.
Here's another tip: to add items to a combo box look at the Field object's setItems method.

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

slzamora
Registered: Jan 4 2008
Posts: 20
For me it seems that the reference files leave "pieces of the puzzle" missing and are geared more to experienced programmers. I'm trying to learn what I need to know to enhance the forms I create; I don't need a degree in the science of JavaScript... but maybe therein lies the problem!

Thank you so very much (bold, capitalized, italicized, underlined) for your diligent help. I really appreciate your assistance! Maybe someday I'll be knowledgeable enough to solve some problems out here too!

sz
Dimitri
Expert
Registered: Nov 1 2005
Posts: 1389
Hi slzamora,

If you are not committed to only a paper book, you should check out www.pdfscripting.com as a training resource for Acrobat and PDF scripting ( including LiveCycle Designer). There are over 13 hours of video snippets on different scripting topics plus loads of copy-n-paste scripts and a library of files for download- so you can learn by both watching and seeing the code in the files. I am from the compnay that publishes the site and we tried to make it a great resource for both beginners and more advanced scripters.


Hope this helps,

Dimitri
WindJack Solutions, Inc
www.pdfscripting.com
www.windjack.com
try67
Expert
Registered: Oct 30 2008
Posts: 2398
How could I forget... Yes, WindJack's tutorials are also a great way to get started with scripting for Acrobat.

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

slzamora
Registered: Jan 4 2008
Posts: 20
Thank you Dimitri and try67. I've discovered pdfscripting.com and perused the free content. Right now I personally can't afford the fees to find out what's available for members, neither will the agency I work for pay them.

Dimitri: Feel free to pass along to Thom that I am very appreciative of one of his tutorials that I found about using a combo box to populate other fields. It works beautifully and makes my form slick!!

Thank you both!