Hello,
You would need to setup ED field with current date and use a JS on a question prior such that the the ED field automatically updates the values on your question choices.
I hope I made sense :-)
Like this?
Qualtrics.SurveyEngine.addOnload(function()
{
// Get the current date from embedded data
var currentDateStr = "${e://Field/CurrentDate}";
var currentDate = new Date(currentDateStr);
// Define your date choices in the format [elementID, date]
var choices = [
['q://QID1/1', new Date('2023-09-11')],
['q://QID1/2', new Date('2023-10-02')],
// Add more choices here
];
choices.forEach(function(choice) {
var elementId = choice[0];
var choiceDate = choice[1];
// Calculate the date 60 days after the choice date
var expiryDate = new Date(choiceDate);
expiryDate.setDate(choiceDate.getDate() + 60);
// If the current date is after the expiry date, hide the choice
if (currentDate > expiryDate) {
jQuery('#' + elementId).parent().hide()
;
}
});
});
@hmacdermott Where do you get that code? ChatGPT? Trust me, it doesn’t work. It take more than that for a custom Javascript.
Try set your embedded data like this number format
Current Date = ${date://CurrentDate/Y}${date://CurrentDate/m}${date://CurrentDate/d}
Your current date will be save as number (i.e today is Current Date = 20230905)
In the option place Display this Choice only if the following condition is met:
Embedded Data | Current Date | Is Less Than | 20231111 (60 days beyond the date)
I’ve just answer a similar question like this, for more information, check out this topic
Ah, I see. Thank you so much. I will try this!
@hmacdermott Let me know if anything comes up
@dxconnamnguyen Thanks again!!!
Current Date = ${date://CurrentDate/Y}${date://CurrentDate/m}${date://CurrentDate/d} was exactly what I needed and worked great.
@hmacdermott Glad to know that 👍
Like this?
Qualtrics.SurveyEngine.addOnload(function()
{
// Get the current date from embedded data
var currentDateStr = "${e://Field/CurrentDate}";
var currentDate = new Date(currentDateStr);
// Define your date choices in the format [elementID, date]
var choices = [
['q://QID1/1', new Date('2023-09-11')],
['q://QID1/2', new Date('2023-10-02')],
// Add more choices here
];
choices.forEach(function(choice) {
var elementId = choice[0];
var choiceDate = choice[1];
// Calculate the date 60 days after the choice date
var expiryDate = new Date(choiceDate);
expiryDate.setDate(choiceDate.getDate() + 60);
// If the current date is after the expiry date, hide the choice
if (currentDate > expiryDate) {
jQuery('#' + elementId).parent().hide()
;
}
});
});
Like this?
Qualtrics.SurveyEngine.addOnload(function()
{
// Get the current date from embedded data
var currentDateStr = "${e://Field/CurrentDate}";
var currentDate = new Date(currentDateStr);
// Define your date choices in the format [elementID, date]
var choices = [
['q://QID1/1', new Date('2023-09-11')],
['q://QID1/2', new Date('2023-10-02')],
// Add more choices here
];
choices.forEach(function(choice) {
var elementId = choice[0];
var choiceDate = choice[1];
// Calculate the date 60 days after the choice date
var expiryDate = new Date(choiceDate);
expiryDate.setDate(choiceDate.getDate() + 60);
// If the current date is after the expiry date, hide the choice
if (currentDate > expiryDate) {
jQuery('#' + elementId).parent().hide()
;
}
});
});
That looks about right… I would need to test it out on a dummy survey to confirm. Thanks!