How to randomly draw one of the rows in a biploar matrix and display the choice of the respondent? | XM Community
Skip to main content

Dear community,
I have a 10-row bipolar matrix in which the respondent chooses between option A and B. In the survey flow I set up a randomisation element, which picks a random number between 1 and 10. This number reflects a randomly drawn row of the bipolar matrix. I pipe the random number to a descriptive text and would like display the respondent's choice (A or 😎 in that particular, random row (1-10).
Is there any smart way to implement this (with or without JS)?
Cheers

Instead of generating a random number, use a randomizer to pick one of ten embedded data blocks with the recode and choice text. Here is an example with 2 embedded data blocks:
image.pngThen pipe randRecode and randChoice into JavaScript, parse randChoice with split() and then use randRecode to choose the left or right string.


Ok, great. Thanks for the tip. Can you also provide me with the JS code? I'm a novice to JS and I've no clue how to use the split function.


https://www.qualtrics.com/community/discussion/comment/27105#Comment_27105var rcArr = "${e://Field/randChoice}".split("||QBipolarDelim||");


As a follow-up: I would like to then use the decision of the participant (A or 😎 in a randomly drawn decision situation (1-10) and calculate his prize in that lottery.
image.pngTo do so, I need another random draw. Either drawing I or II with different probabilities (depending on the randomly drawn decision situation 1-10) or drawing 1 - 10 in which e.g. (decision situation 2) 1 and 2 represent I and 3-10 represent II.


I got the first bit, the random draw of a decision situation:
image.pngWe randomly drew decision number ${e://Field/randRecode}, in which you selected lottery ${e://Field/randChoice}
With the JS code looking as follows:
var rcArr = "${e://Field/randChoice}".split("||QBipolarDelim||"); 
Yet, as you see in the screenshot, the random decision number is not followed by the correct description text (needs to be linked) and I don't know how to display the actual decision of the participant (A or B/left or right).
Any ideas how to link randRecode and randChoice and how to display randChoice and not the descriptive text?


https://www.qualtrics.com/community/discussion/comment/27231#Comment_27231rcArr is an array where rcArr[0] is the left label and rcArr[1] is the right label. randRecode is the answer selected where 1 is left and 2 is right (you could recode them to 0 and 1 to match the rcArr indices).
To show what they selected you need some html and JS.
html where you want to pipe the selected choice text:

JS:
jQuery("#choiceText").html(rcArr[parseInt("${e://Field/randRecode}")-1]);
If you want to pipe the random row number, you need to add another field to your embedded data blocks (e.g., randRow = 1).


Leave a Reply