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

document level javascripts

Registered: Jun 28 2011
Posts: 3

Can someone direct me on how to set focus to a text field on opening a pdf and also clear the form? I've tried a document level javascript and I can't get it to execute.

My Product Information:
Acrobat Pro 9.0, Windows
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4311
Do you have JavaScript enabled for the Acrobat/Reader application?

Are you getting any errors on the JavaScript console?

What is the code you are trying to run?

Do you want the scripts to include clearing the form upon opening and a by a user button. The user button can also include a confirmation prompt before clearing the form.

George Kaiser

Registered: Jun 28 2011
Posts: 3
Under the preferences tab I have the enable acrobat javascript checkbox checked
this.resetForm();
'to clear form fields
this.getField("Day").focus();
'to set focus to this field
and I have set the document javascript to the function with this code
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4311
When I copy your code to the document level JavaScript and save it, I get a message about an unterminated string literal. This is JavaScript and the comments are indicated by '//' for a single line comment or "/*" and "*/" for a multi line comment.

The method to move a cursor to a given field is '.setFocus()', so your line needs to read 'this.getField("Day").setFocus();".

If you use a defined function or undefined function to run your code, you will benefit from some optimization within Acrobat JavaScript. Using a defined function will also allow you more easily text your form without having to save, close, and open the form.

function init() {
this.resetForm(); // to clear form fields
this.getField("Day").setFocus(); // to set focus to this field
return true; // indicate successful completion
}

init();

You might want to link your web bowser to or download the Acrobat JS API Reference.

George Kaiser

Registered: Jun 28 2011
Posts: 3
When I open the pdf form how can I perform a calculation to know the number of days in a form field since January 1,2000 to today's date for further calculation or the date to be populated. I have a date field and have set it to display the today's date onfocus. Can I set it to automatically update the date when the pdf is opened?