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

Problems Auto-populating Date On Page Opening

New Here ,
Mar 22, 2023 Mar 22, 2023

I am having problems auto-populating individual day, month and year fields of my form when the form is being opened.

When I open the form, I am getting these errors:

"Invalid date/time: Please ensure that the date/time exists. [Day] should match format d"

"Invalid date/time: Please ensure that the date/time exists. [Month] should match format mmm"

 

I have in my forms, fields named "Day", "Month", and "Year". They are all of a date format, with a custom format for "Day" being d, and for "Month" mmm and for "Year" yyyy. All three are set as "Read Only" and "Required"

I put this JavaScript event in the ACTIONS tab of the PAGE PROPERTIES of the page with the fields I am trying to populate.

var fd = this.getField("Day");
fd.value = util.printd("d", new Date());
var fm = this.getField("Month");
fm.value = util.printd("mmm", new Date());
var fy = this.getField("Year");
fy.value = util.printd("yyyy", new Date());

The properties in the EVENTS tab are:

Select trigger: Page Open

Select action: Run a JavaScript

I save the document, and when I run, I get the errors. When I go back to the Page Properties to check the event, the select action had changed to "Execute a menu item". I can't seem to keep "Run a JavaScript" as the preferred parameter.

The action box does reflect run a JS on page open.

 

Where am I going wrong?

TOPICS
PDF forms
640
Translate
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
2 ACCEPTED SOLUTIONS
Community Expert ,
Mar 22, 2023 Mar 22, 2023

Set the Format setting of these fields to None.

View solution in original post

Translate
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 ,
Mar 22, 2023 Mar 22, 2023

It should show "Mar"... Do you use a different locale on your computer?

And the year should work fine, too. Are you sure there aren't any errors in your code? Check the JS Console (Ctrl+J).

View solution in original post

Translate
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 ,
Mar 22, 2023 Mar 22, 2023

Set the Format setting of these fields to None.

Translate
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 ,
Mar 22, 2023 Mar 22, 2023

Thank you try67!

Almost there, but still a couple problems.

I am wishing my month to be expressed as "Mar" for March as an example. What I am getting now is simply "Ma"

The year, expecting "2023", is empty.

Translate
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 ,
Mar 22, 2023 Mar 22, 2023

It should show "Mar"... Do you use a different locale on your computer?

And the year should work fine, too. Are you sure there aren't any errors in your code? Check the JS Console (Ctrl+J).

Translate
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 ,
Mar 22, 2023 Mar 22, 2023
LATEST

Awesome! Got it working.
Turns out I had some residual settings from when I was manually entering the data into these fields. I had a limit of two characters set in the options that restricted the values.

The JS Console revealed at error in my JS ... one of my variables was inconsistent.

Thank you once again!

Translate
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