I have a question in a survey asking the date of the class. I have the default choice as today ${date://CurrentDate/SL} How can I create an embedded data field for the Day of the Week and Month name from this response?
Solved
Extracting day of the week and month name as embedded data from answer
Best answer by vgayraud
Hi
Create 2 EDs in your survey flow named selectedDay and selectedMonth and add this code to your question.
Qualtrics.SurveyEngine.addOnPageSubmit(function()
{
const date = new Date(jQuery("#"+this.questionId+" .InputText").val());
const days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
const months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
Qualtrics.SurveyEngine.setEmbeddedData('selectedDay', days[date.getDay()]);
Qualtrics.SurveyEngine.setEmbeddedData('selectedMonth', months[date.getMonth()]);
});
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.