How to run JAVAScript in Qualtrics based on selected value | XM Community
Question

How to run JAVAScript in Qualtrics based on selected value

  • 22 October 2020
  • 1 reply
  • 12 views

Hi all. Let us say I have a question that asks which term the students are considering. Based on that selection I want to capture that value and run the javascript. But after it runs I want use the outcome of the javascript to send the students to a different block of questions.
Here is the JAVASCRIPT I have., Also, I am not sure if there is a video that explains where in the sequence of questions you would embed the javascript
Thanks for the help.

var spring_start_date = "02-01-2021";
var summer_start_date = "02-05-2021";
var fall_start_date = "02-08-2021";
var term_option = '{term_selection}';
var term = {"Fall 2021": fall_start_date, "Summer 2021": summer_start_date,
"Spring 2021": spring_start_date};
var startofterm = moment(term[term_option], 'DD-MM-YYYY');
var today = moment();
var days_diff = -startofterm.diff(today,'days');

if (days_diff <= 7) {
  1;   
} else if (days_diff <= 14) {
  2;
} else if (days_diff <= 21) {
  3;
} else {
  4;
}


1 reply

Userlevel 7
Badge +22

Set an embedded data based on the if consition and use this embedded data in display logic to show respective block of questions.

Leave a Reply