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

Question

Question

Javascript day of week in collection

asked on March 28, 2017 Show version history

Hi everyone.

i have a form with a date field and a dropdown list.

my intention is to populate the dropdown field automatically with the day chosen from the date picker. it works fine when the fields are not in a collection but doesn't work at all within a collection.

Example :28-03-2017 will populate the dropdown with "Tuesday"

Any help will be greatly appreciated.

 

$(document).ready(function () {
function findDay() {
var d = new Date($('#Field15').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');
}
$('.startDate').on('change', 'input', findDay);
});

 

0 0

Answer

SELECTED ANSWER
replied on March 28, 2017 Show version history

Sorry, as a Collection the variable needs to be defines differently

This worked in version 10.1 and 10.2

=CHOOSE(WEEKDAY(INDEX(Collection.Pick_a_Date,ROW())),"SUNDAY","MONDAY","TUESDAY","WEDNESDAY","THURSDAY","FRIDAY","SATURDAY")

Easiest to place the variable using the > feature in Calculations.

Otherwise "Collection" represents the Variable name of the Collection, followed by "." and the Variable name for the Date field (created in the collection)

1 0

Replies

replied on March 28, 2017 Show version history

Hi Claudette

If the end result is you just want to display the Day of the week in a Field, and it doesn't have to be a drop down, another option is to use a Single Line Field in your collection with the following Formula in the Calculation field. The Date in the formula would be your Date Field Token

=CHOOSE(WEEKDAY(Date),"SUNDAY","MONDAY","TUESDAY","WEDNESDAY","THURSDAY","FRIDAY","SATURDAY")

Example (this was using Forms 10.1)

0 0
replied on March 28, 2017

Hi Steve,

Yes i don't mind if its a single field. it can be any field, i just need to display it to the user.

i tried it now but it also does not work in a collection.

Any other ideas please?

 

0 0
SELECTED ANSWER
replied on March 28, 2017 Show version history

Sorry, as a Collection the variable needs to be defines differently

This worked in version 10.1 and 10.2

=CHOOSE(WEEKDAY(INDEX(Collection.Pick_a_Date,ROW())),"SUNDAY","MONDAY","TUESDAY","WEDNESDAY","THURSDAY","FRIDAY","SATURDAY")

Easiest to place the variable using the > feature in Calculations.

Otherwise "Collection" represents the Variable name of the Collection, followed by "." and the Variable name for the Date field (created in the collection)

1 0
replied on March 28, 2017

See update above

0 0
replied on March 29, 2017

Thanks a lot Steve. 

it works perfect. :)

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

Sign in to reply to this post.