Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Javascript auto fill in date fields from reference field

New Here ,
Jun 05, 2021 Jun 05, 2021

Copy link to clipboard

Copied

I have a expense form that lists each day of the week. The form has a main date field that the user selects the Saturday date from a drop down calendar. I would like to have the individual days to have the date autofill. Does anyone know the Javascript that will calculate a date from an existing field.

 

Example  If Main Date Field is entered 6/5/2021 (always a Saturday Date), I would like the previous days date to autofill.  Sunday Date field would auto fill with the date 5/30/2021, Monday Date field 5/31/2021, etc for each day of the week through Saturday showing 6/5/2021.  Is this possible?

 

Thanks in advance.

TOPICS
JavaScript

Views

275

Likes

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

Adobe Community Professional , Jun 05, 2021 Jun 05, 2021
Here is some basic script you can easily adapt (if you wish so) I set field names as week days, you can change that to your actual field names, use script as validation script of "Saturday" field: if(event.value == ""){ this.getField("Friday").value = ""; this.getField("Thursday").value = ""; this.getField("Wednesday").value = ""; this.getField("Tuesday").value = ""; this.getField("Monday").value = ""; this.getField("Sunday").value = "";} else{ var d1 = util.scand("m/d/yyyy", event.value) d1.set...

Likes

Translate

Translate
Adobe Community Professional ,
Jun 05, 2021 Jun 05, 2021

Copy link to clipboard

Copied

Here is some basic script you can easily adapt (if you wish so) I set field names as week days, you can change that to your actual field names, use script as validation script of "Saturday" field:

if(event.value == ""){
this.getField("Friday").value = "";
this.getField("Thursday").value = "";
this.getField("Wednesday").value = "";
this.getField("Tuesday").value = "";
this.getField("Monday").value = "";
this.getField("Sunday").value = "";}
else{
var d1 = util.scand("m/d/yyyy", event.value)
d1.setDate(d1.getDate() -1);
var d2 = util.scand("m/d/yyyy", event.value)
d2.setDate(d2.getDate() -2);
var d3 = util.scand("m/d/yyyy", event.value)
d3.setDate(d3.getDate() -3);
var d4 = util.scand("m/d/yyyy", event.value)
d4.setDate(d4.getDate() -4);
var d5 = util.scand("m/d/yyyy", event.value)
d5.setDate(d5.getDate() -5);
var d6 = util.scand("m/d/yyyy", event.value)
d6.setDate(d6.getDate() -6);

this.getField("Friday").value = util.printd("m/d/yyyy", d1);
this.getField("Thursday").value = util.printd("m/d/yyyy", d2);
this.getField("Wednesday").value = util.printd("m/d/yyyy", d3);
this.getField("Tuesday").value = util.printd("m/d/yyyy", d4);
this.getField("Monday").value = util.printd("m/d/yyyy", d5);
this.getField("Sunday").value = util.printd("m/d/yyyy", d6);}

Likes

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 ,
Jun 13, 2021 Jun 13, 2021

Copy link to clipboard

Copied

LATEST

It works.  Thanks!

Likes

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