-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// This script is a demo of adding/modifying Embedded Data variables based on events on the page. | ||
|
||
// The script shown below allows you to add/modify Embedded Data variables as soon as the choices are submitted. | ||
|
||
// This allows more flexibility than the "Set Embedded Data" option in the "Survey Flow" section, as that works at block level, while this one works at Page level. | ||
|
||
// By modifying it a bit and adding it to the addOnReady() or addOnLoad() section, you can even recorded choices that were selected and then unselected. | ||
|
||
Qualtrics.SurveyEngine.addOnPageSubmit(function (type) { // To record the selection when the page is submitted | ||
if (type == "next") { | ||
var selChoice = this.getSelectedChoices(); // Get the selected choices | ||
var choiceRef = ""; | ||
var choiceText = ""; | ||
for (let i = 0; i < selChoice.length; i++) { //Loop over all the choices selected in the question | ||
choiceRef = "#" + this.questionId + "-" + selChoice[i] + "-label > span"; // Create a reference for the choices | ||
choiceText = document.querySelector(choiceRef).innerHTML; //Get the value (The actual text displayed)of the choices from the webpage | ||
|
||
// Set Embedded Data | ||
|
||
if (choiceText.includes("Share")) { | ||
Qualtrics.SurveyEngine.setEmbeddedData("Share", "TRUE"); | ||
} else | ||
Qualtrics.SurveyEngine.setEmbeddedData("Share", "FALSE"); | ||
|
||
} | ||
} | ||
}); |