Selecting choices from Unselected choices | XM Community
Solved

Selecting choices from Unselected choices

  • 2 January 2019
  • 2 replies
  • 90 views

Userlevel 1
Badge +2
I am creating a survey that is based on multiple choice questions. The first block in the survey contains the questions and based on what the user selects (user can select only one option), a succeeding block will contain specific statements from the Unselected Choices, e.g. if the user selects options a from q1, the succeeding block can contain option c from q1 and similarly for all other questions. Currently I am using Display Logic but since there are 16 questions and each have 6 options, Display Logic will not be feasible. Since I am a beginner at JS, I was wondering if this logic could be implemented with JS and how?
icon

Best answer by fleb 2 January 2019, 22:08

View original

2 replies

Userlevel 5
Badge +6
Hi @R_I,
yes, it could.
1) Put HTML element with a defined ID exactly there where you want one of the unselected options to be displayed. It is better when it contains some arbitrary text and I recommend you to use a different one for each question. An example: ` <div id="demo" >Here will be a random unselected choice</div>`
2) Add following JavaScript to the question where your HTML element is.

Qualtrics.SurveyEngine.addOnload(function()
{
var unselected = "${q://QID1/ChoiceGroup/UnselectedChoices}".split(", ");;
var i = Math.floor(Math.random() * unselected.length);
document.getElementById("demo").innerHTML = unselected[i];
Qualtrics.SurveyEngine.setEmbeddedData( "random_choice", unselected[i] );

});

The first line takes all unselected choices texts and splits it using this separator ", " since they were stored in one string. In case the separator is present in choices themselves, the code won't run correctly. In this case I'd recommend you to get the unselected choices by modifying the code from this discussion and add there some separator which is not present in your choice texts.
The second line randomly generates a number which will be used as an index of randomly selected unselected 😃 choice. (More details here.)
The third line puts the choice into your "demo" HTML element.
The last line sends the choice to an embedded data field. Without this line you wouldn't know which choice was used during data analysis. Note that you have to define the embedded filed in the survey flow.
@fleb's code works, but there is a problem:

If the survey page is reloaded (and this happens, for example, if a respondent tries to skip a "Force Response" question), the page runs the code again, and the respondent sees another randomly selected choice.

This could have an effect on respondent behaviour. Coud the code be altered to stop this happening?

Leave a Reply