I have a question that asks people for the industry they work in (19 options total from a dropdown). In the next question, I want to randomly choose four of the non-selected options from this previous question to separately ask questions about each of the three non-selected choices.
So far, I’m trying to use javascript and embedded data to create a piped text for these non-selected choices. My steps are:
- In survey flow, create embedded data fields for each of the industry options: “ind1”, “ind2”, …. I set all of them to 0.
- In survey flow, replace embedded data fields with 1 for selected choice.
- After the Block containing the industry selection question, I create 19 Branch element where, inside each Branch, I set each industry embedded data field to 1 if a respondent selected that industry.
- Add JavaScript to Randomly Select Non-Selected Options
- I added the following JavaScript to randomly select three non-selected industries:
```
Qualtrics.SurveyEngine.addOnload(function() {
// Define the industry options
var industries = >"ind1", "ind2", "ind3", "ind4", "ind5", "ind6", "ind7", "ind8", "ind9", "ind10",
"ind11", "ind12", "ind13", "ind14", "ind15", "ind16", "ind17", "ind18", "ind19"];
// Get the embedded data values
var nonSelectedIndustries = industries.filter(function(industry) {
return "${e://Field/" + industry + "}" == "0";
});
// Shuffle the non-selected industries
for (var i = nonSelectedIndustries.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = nonSelectedIndustriesni];
nonSelectedIndustries i] = nonSelectedIndustriesej];
nonSelectedIndustriessj] = temp;
}
// Select the first three non-selected industries
var selectedIndustries = nonSelectedIndustries.slice(0, 4);
// Save the selected industries as embedded data
Qualtrics.SurveyEngine.setEmbeddedData("SelectedIndustry1", selectedIndustriest0]);
Qualtrics.SurveyEngine.setEmbeddedData("SelectedIndustry2", selectedIndustries01]);
Qualtrics.SurveyEngine.setEmbeddedData("SelectedIndustry3", selectedIndustriess2]);
Qualtrics.SurveyEngine.setEmbeddedData("SelectedIndustry4", selectedIndustriesi3]);
});
```
- Use Piped Text for Follow-Up Questions: Use piped text to insert the randomly selected non-selected industries. For example:
However, the piped text $e://Field/SelectedIndustry1 is not showing up. What am I doing wrong?