• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Adding date in a field, via a link or button.... & extra credit

New Here ,
Oct 04, 2020 Oct 04, 2020

Copy link to clipboard

Copied

I have found many posts abouting autopopulating dates/times into fields.... but what I am looking for is the following...

 

I have a field titled "incident_date",  I want the users to be able to click a button, or a link that says "Today" and it will input the current date.

I have a field titled "incident_time",  I want the users to be able to click a button, or  alink that says "Now" and it will input the current time.

If they don't click one of the links/buttons, I want the users to be able to input a different date (in case they are doing their reports on a a differnt day)

Having it autofill with todays date/time all the time does not work for my situation, as it can be different, and the pdf gets opened often by different users, and I need the date/time to stay the same. 

 

For extra credit, I have check boxes that are titled "am" & "pm" and would like them to be automatically checked in the appropriate check box based off of the current time when the above mentioned button/link is pressed.

 

Fingers crossed!

 

-brando

 

TOPICS
Acrobat SDK and JavaScript

Views

445

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Community Expert , Oct 04, 2020 Oct 04, 2020

You can run everything from one button with a mouse-up action. And to make it simpler the script below for the time takes into account the am/pm format

 

The first script writes the date to the desired date field,  and the the second script writes the time to the desired time field.

 

Using a button writes only once, so the users can edit those fields manually. 

 

The fields will only update to current date and time if it is clicked. 

 

f = this.getField("incident_date");
f.value = util.printd (
...

Votes

Translate

Translate
Community Expert , Oct 04, 2020 Oct 04, 2020

With the "extra credit":

 

var now = new Date();

var f = this.getField("incident_date");
f.value = util.printd("mmm d, yyyy", now);

var g = this.getField("incident_time");
g.value = util.printd("h:MM:ss tt", now);

var am = this.getField("am");
am.checkThisBox(0, now.getHours()<12);

var pm = this.getField("pm");
pm.checkThisBox(0, now.getHours()>=12);

Votes

Translate

Translate
Community Expert ,
Oct 04, 2020 Oct 04, 2020

Copy link to clipboard

Copied

You can run everything from one button with a mouse-up action. And to make it simpler the script below for the time takes into account the am/pm format

 

The first script writes the date to the desired date field,  and the the second script writes the time to the desired time field.

 

Using a button writes only once, so the users can edit those fields manually. 

 

The fields will only update to current date and time if it is clicked. 

 

f = this.getField("incident_date");
f.value = util.printd ("mmm d, yyyy", new Date());

g = this.getField("incident_time");
g.value = util.printd ("h:MM:ss tt", new Date());

 

 

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 04, 2020 Oct 04, 2020

Copy link to clipboard

Copied

With the "extra credit":

 

var now = new Date();

var f = this.getField("incident_date");
f.value = util.printd("mmm d, yyyy", now);

var g = this.getField("incident_time");
g.value = util.printd("h:MM:ss tt", now);

var am = this.getField("am");
am.checkThisBox(0, now.getHours()<12);

var pm = this.getField("pm");
pm.checkThisBox(0, now.getHours()>=12);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 04, 2020 Oct 04, 2020

Copy link to clipboard

Copied

LATEST

Ok sir, you get the extra credit points!

 

This had an unexpected (to me) consiquence, that ended up woring out. I was wanting each button to do each field... So if/when they clicked the button called "TODAY" it would fill in the date, and if /when they clicked the "NOW" button it would fill in the time....

 

I split up the code you gave me to:

(TODAY button) var now = new Date(); var f = this.getField("incident_date"); f.value = util.printd("mm/dd/yyyy", now) 

 

(NOW button) var now = new Date(); var f = this.getField("incident_date"); f.value = util.printd("mm/dd/yyyy", now); var g = this.getField("incident_time"); g.value = util.printd("h:MM", now); var am = this.getField("am1"); am.checkThisBox(0, now.getHours()<12);
var pm = this.getField("pm1"); pm.checkThisBox(0, now.getHours()>=12);

 

When the now button is clicked, the date and time is filled in.. obviuosly, if they are clicking the "now" button to get the current time... it would be the current date as well!

 

Thanks for the quick response and knowledge!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines