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

Beginner Scripting Question

Lady Di
Registered: Feb 18 2009
Posts: 86
Answered

Please excuse my ignorance on this topic. This is my first try at writing JavaScript and I am not having much luck. I tried to write two lines of script in the "Document JavaScript" of my form. I wanted to name my form and I want a field on the form to automatically show the current date when information is added to the form. This is the code that I have, but it doesn't seem to work -- function Name() {FormName = "FiveHundred"} and function CurrDate() {FiveHundredForm.Date_Completed.Value = (Date ());}

Any assistance you can provide would be greatly appeciated.

My Product Information:
Acrobat Pro 8.0, Windows
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
You need to clarify for us when you want the date field to be updated. There are a number of possibilities, including:

1. Every time the form is opened
2. Only the first time the form is opened
3. Whenever any field value changes in the form
4. At the time that the form data is submitted to a web server/email
5. When the form is saved
6. etc.
7. etc.

Also, is the name of your date field "Date_Completed"?

Finally, are you creating your form in Acrobat, or are you using LiveCycle Designer?

George
Dimitri
Expert
Registered: Nov 1 2005
Posts: 1389
Hi Lady Di,

Have you searched the forums here for Date and Time Calculations? You will find many threads on the subject as well as script examples. In addition, there is a 3 part tutorial on using Date and Time scripts in PDF forms in the Learning Center (as well as over 60 articles on using JavaScript for a wide variety of tasks in Acrobat and PDF documents and Forms). Here is a link to Part 1 of a 3 part series-
http://www.acrobatusers.com/tutorials/2006/date_time_part1



If you would like a training course and comprehensive set of scripting resources for Acrobat PDF and LiveCycle Designer PDF forms the best overall resource available is www.pdfscripting.com


Hope this helps,

Dimitri
WindJack Solutions
www.pdfscripting.com
www.windjack.com
Lady Di
Registered: Feb 18 2009
Posts: 86
I would like the date field to be updated when the form is submitted to e-mail if I can.

Yes, the name of my date field is Date_Completed.

I am creating the form in Acrobat Professional 8.0.
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
Dimitri has pointed you to some good resources for learning more, and you'll also want to get the Acrobat JavaScript reference and the accompanying Scripting Guide to learn more about JavaScript programming in Acrobat.

With Acrobat forms, there is no need (and no means) to name a form like you can do with HTML forms. The document object model (DOM) is entirely different than a browser-based DOM, so you'll have to get used to doing things differently.

When setting up a form to "submit" via email, you'd normally set up a button to have a "Submit a form" type of action and specify a mailto type URL. Buttons can have multiple actions associated with an event (you should use the Mouse Up event for this), so your submit button's first action should be a JavaScript that sets the date field to the current date. The second action should be the submit action.

For setting the field value to the date, you really do not need to use a document-level script. The code in the button's Mouse Up event could look something like the following:

getField("Date_Completed").value = util.printd("mm/dd/yyyy", new Date());
You may want to use a different date format, but you should get the idea. See the Acrobat JavaScript reference for more information on the getField and util.printd methods. The resources Dimitri mentioned will be very helpful as well.

George
Lady Di
Registered: Feb 18 2009
Posts: 86
I used the code you provided and I researched the links that Dimtri provided. However, I am still having trouble with this. The date is only visible when you click on or tab to the specified field.
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
When you bring up the Text Field Properties dialog, what is specified under the Format or Calculate tabs? How about the font color?
Lady Di
Registered: Feb 18 2009
Posts: 86
There is nothing specified on the calculate tab. The format tab is set to date: m/d/yy. The font color is set to black.
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
Set the format to None and see what happens. Since you're setting the date to the format you want in code, you do not need to specify a format there.