Skip to main content
betsyboop124
Inspiring
February 19, 2021
Answered

PDF Form - Auto Date Dropdown Field Needs to Default to Today

  • February 19, 2021
  • 1 reply
  • 1987 views

I'm using this code to populate a dropdown with dates 30 days prio to today and 60 days after today. The client would like for Today to be selected by default when the form is opened. I appreciate any help you can give. 

 

var aDateList = [];

var nToday = (new Date).getDate();

var dtItem;

for(var i=-30;i<60;i++)

{

dtItem = new Date;

dtItem.setDate(nToday + i);

aDateList.push(util.printd("mm/dd/yyyy", dtItem));

}

this.getField("DateList").setItems(aDateList);

This topic has been closed for replies.
Correct answer betsyboop124

I am still struggling with that script.

 

I only get 30 dates listed, not 30 in the past and 60 in the future.


Thanks for taking the time. My dates as of today are 1/26 - 4/25. I showed the client the latest dropdown with "Please Select" and she is happy with it, When the user clicks it to select it jumps to and selects today's date.

 

Thanks again!

1 reply

Nesa Nurani
Community Expert
Community Expert
February 20, 2021

I assume you are using code as document level script?

Add this code at the bottom of your code:

var dt = this.getField("DateList");
dt.value = util.printd("mm/dd/yyyy", new Date());

betsyboop124
Inspiring
February 22, 2021

Hi thanks for the reply. I'm using the code in a  PDF form dropdown field. The code is located in Actions OnFocus - Javascript Action. As you mayy have figured out, I'm a newbie who knows almost nothing about Javascript. Would the code you provided go into the code I supplied? If so where.

 

Thanks again.