Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
52
rated 0 times [  59] [ 7]  / answers: 1 / hits: 45237  / 14 Years ago, fri, july 16, 2010, 12:00:00

The goal is for an Acrobat form to fill a date field (MeetingDate) with Today's date when the user opens it. If the user saves the form as is and opens it a few days later, the old date should still be there, not replaced by the current date. If the user changes date in the field, that date should be saved and should not be replaced when the form is opened later.



I have a Custom Calculation Script for a date field (MeetingDate) that does all of this, but with one problem:



if (event.value != )
then
event.value = util.printd (m/d/yyyy, new Date())
endif


This works well except that after entering the script, today's date fills in the MeetingDate field and the value is saved. That makes sense, but I want the field to be automatically filled with Today's date when the user opens the form. Instead, if the user opens the form tomorrow (7/16/2010) it will have 7/15/2010 in the field because that is the date I saved the form.



I think the answer may be to enter a script as a Document JavaScript (Advanced | Document Process | Document JavaScripts), since Document scripts execute when the form is opened, but all my attempts cause a date entered by the user to be overwritten when the form is opened days later. Thanks for the help!


More From » forms

 Answers
8

Remove your script and replace it with the following document javascript:



var f = this.getField(wells_datefield);
if (!f.value) f.value = util.printd (m/d/yyyy, new Date());


Save your form and open it, and the date should pop right in there.



When making the document javascript, remember to not put it inside a function. One way of doing that is the following. In the Acrobat menu:




  1. Advanced->Document Processing->Document Javascripts...

  2. In the dialog that pops up, enter a Script Name (for instance populate_date) and click Add...

  3. In the script dialog that pops up: REMOVE everything (function populate_date(){}) and paste in the script above.

  4. Click ok, then Close.

  5. Save the form, close it and reopen it.

  6. There is no step 6! :>


[#96214] Tuesday, July 13, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
raymondd

Total Points: 620
Total Questions: 112
Total Answers: 94

Location: Namibia
Member since Mon, Feb 21, 2022
2 Years ago
raymondd questions
Thu, Apr 22, 21, 00:00, 3 Years ago
Thu, Jul 9, 20, 00:00, 4 Years ago
Thu, Apr 9, 20, 00:00, 4 Years ago
Thu, Jul 25, 19, 00:00, 5 Years ago
;