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.
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);}
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);}
Copy link to clipboard
Copied
Well you are just fantastic! That worked beautifully. Thank you so much! š
Copy link to clipboard
Copied
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?