Skip to content

Commit

Permalink
Added function for complex display logic
Browse files Browse the repository at this point in the history
  • Loading branch information
tafakkur committed Dec 9, 2020
1 parent 9df6fb6 commit dad2ec7
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions JavaScript Files/Complex Display Logic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Qualtrics.SurveyEngine.addOnload(function () {
// Hide the question as soon as the page loads
this.getQuestionContainer().hide();

//Variable to decide whether to show the question or not. Initially false
show_answer = false;

//Create an embedded variable with all the valid choices using a seperator
// In this a comma "," is used
var valid_choices = "${e://Field/valid_choices}";
valid_choices = valid_choices.split(",");

//Get your entered choice. This is showning an embedded variable
// Which you can set based on your question type.
const entered_choice = "${e://Field/entered_choice}";

// Check if the entered choice is equal to any of the valid choices
valid_choices.forEach((item) => {
if (item.trim() == entered_choice) {
show_answer = true;
}
});

//Show the question, if the condition is met
if (show_answer == true) {
this.getQuestionContainer().show();
}

//Optionally you can add a condition to click the next button
// If you only have that one question on the page
if (show_answer == false) {
this.clickNextButton();
}
});

0 comments on commit dad2ec7

Please sign in to comment.