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

Autofill expiration date to last day of the year based off of another date field

New Here ,
Jan 20, 2023 Jan 20, 2023

Copy link to clipboard

Copied

I need to set up an auto-fill date field that is the last day of the year based off of another date field.

Example: "Requested Start Date" field is 1/23/23, I need the "Expiration Date" field to auto-fill as 12/31 of the same year as the Requested Start Date Field (so it would be 12/31/23). If someone selects 2/2/24 as start date, I need the expiration date field to be 12/31/24, etc. The expiration date always needs to be the last day of the year of the start date field.

 

Can anyone help me with the javascript code to do this? I am struggling to get it to work.

TOPICS
JavaScript , PDF forms

Views

128

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 1 Correct answer

Community Expert , Jan 20, 2023 Jan 20, 2023

Use this as validation script of "Requested Start Date" field:

var date = util.scand("mm/dd/yy", event.value);
if(event.value == "")
this.getField("Expiration Date").value = "";
else{
var year = date.getFullYear()+1;
var str = year.toString();
this.getField("Expiration Date").value = "12/31/"+str.slice(2,4);}

 

Votes

Translate

Translate
Community Expert ,
Jan 20, 2023 Jan 20, 2023

Copy link to clipboard

Copied

Use this as validation script of "Requested Start Date" field:

var date = util.scand("mm/dd/yy", event.value);
if(event.value == "")
this.getField("Expiration Date").value = "";
else{
var year = date.getFullYear()+1;
var str = year.toString();
this.getField("Expiration Date").value = "12/31/"+str.slice(2,4);}

 

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 ,
Jan 20, 2023 Jan 20, 2023

Copy link to clipboard

Copied

Well you are just fantastic! That worked beautifully. Thank you so much! 🙂

 

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 ,
Jan 20, 2023 Jan 20, 2023

Copy link to clipboard

Copied

LATEST

Well, bugger. Now I just found out that the expiration date should only autofill if the "Annual" box is checked. If "One Time Use" box is checked, they need to fill in the expiration date manually.

 

Any way to make that happen?

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