You are viewing limited content. For full access, please sign in.

Question

Question

day of the week

asked on March 17, 2016 Show version history

In my form, I use a date field which is configured as a default value of 'Today' so the users do not have to click on the calendar icon and select the current date.  Works great.

Now, I wanted to have a field below it displaying the day of the week.  I found code on a posting from this site that does that.

My issue is this.  The code only executes when the user enters a date by either typing one in or clicking the date calendar icon.  The date is already in that field upon page load because Forms is configured to use the default of Today.

I would like to know if the code can be changed so that it recognizes a date is already in the field and thus displays the day of the week.

 

$(document).ready(function () {
function findDay() {
var d = new Date($('#Field79').val());
var weekday = new Array(7);
weekday[0]= "Sunday";
weekday[1] = "Monday";
weekday[2] = "Tuesday";
weekday[3] = "Wednesday";
weekday[4] = "Thursday";
weekday[5] = "Friday";
weekday[6] = "Saturday";
var n = weekday[d.getDay()];
$('.dayWeek select').val(n);
$('.dayWeek select').trigger('change');
}
$('.WORK').on('change', 'input', findDay);
});

0 0

Replies

replied on March 17, 2016

You can call the findDay function as soon as the document is ready and also have it run when the date is changed.

$(document).ready(function () {
  
  findDay();
  
  function findDay() {
    var d = new Date($('#Field79').val());
    var weekday = new Array(7);
    weekday[0]= "Sunday";
    weekday[1] = "Monday";
    weekday[2] = "Tuesday";
    weekday[3] = "Wednesday";
    weekday[4] = "Thursday";
    weekday[5] = "Friday";
    weekday[6] = "Saturday";
    var n = weekday[d.getDay()];
    $('.dayWeek select').val(n);
    $('.dayWeek select').trigger('change');
  }
  
  $('.WORK').on('change', 'input', findDay);
  
});
1 0
replied on March 17, 2016

That is exactly what I was looking for.  Thanks!!yes

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.