Skip to main content
Participant
September 20, 2017
Answered

Need Day of Week to Autofill

  • September 20, 2017
  • 1 reply
  • 3715 views

Is there a way to have a user enter a date, and have another (hidden) field automatically show what day of the week that date falls on? (i.e. they enter 9/20/17 into a date field, and next to it another field automatically shows Wednesday.)

This topic has been closed for replies.
Correct answer try67

Actually, this is a bit neater...

var s = this.getField("Date").valueAsString;

event.value = "";

if (s!="") {

    var d = util.scand("m/dd/yy", s);

    if (d!=null) event.value = util.printd("dddd", d);

}

1 reply

try67
Community Expert
Community Expert
September 20, 2017

Use this code as the custom calculation script of the second field. Adjust the field name in line #2, if necessary.

var days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];

var s = this.getField("Date").valueAsString;

event.value = "";

if (s!="") {

    var d = util.scand("m/dd/yy", s);

    if (d!=null) event.value = days[d.getDay()];

}

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
September 20, 2017

Actually, this is a bit neater...

var s = this.getField("Date").valueAsString;

event.value = "";

if (s!="") {

    var d = util.scand("m/dd/yy", s);

    if (d!=null) event.value = util.printd("dddd", d);

}