Skip to main content
Participating Frequently
March 22, 2023
Answered

Problems Auto-populating Date On Page Opening

  • March 22, 2023
  • 1 reply
  • 825 views

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?

This topic has been closed for replies.
Correct answer try67

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).

1 reply

try67
Community Expert
March 22, 2023

Set the Format setting of these fields to None.

Jenn MC2Author
Participating Frequently
March 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.

try67
try67Correct answer
Community Expert
March 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).