I want to roll a dice once and to store the result as embedded data to use it later in the survey. The dice rolls well, BUT I CAN'T STORE THE RESULT. These are the steps that I followed.
1- In the beginning of the survey flow, I created a new field: result_matrix_embedded (I did not set it equal to any value)
2- This is what I wrote in the JavaScript of the question: I am using some code that I found online from Philip Tschiemer
Qualtrics.SurveyEngine.addOnload(function()
{
// Required for the callback functions to work.
var self = this;
// For our comfort, the common settings are predefined.
var value_set = [
{key:"1",probability:1},
{key:"2",probability:1},
{key:"3",probability:1},
{key:"4",probability:1},
{key:"5",probability:1},
{key:"6",probability:1}
];
var images = {
base_url:'https://www.descil.ethz.ch/projects/1305-SensQuest/dice/img/',
ext:'.png',
init: 'qmark1.png'
};
new Dice("dice1","throw1",{
possible_throws: 1,
value_set: value_set,
images: images,
result_callback: function(throw_nr,result_key){
Qualtrics.SurveyEngine.setEmbeddedData('result_matrix_embedded'+ throw_nr, result_key);
}
});
});
3- This is what I wrote in the HTML:
<strong>Are you ready to roll the dice?</strong><br />
<br />
If yes, roll the dice below by clicking on the button.
<br /><br /><br />
<script src="https://www.descil.ethz.ch/projects/1305-SensQuest/dice/dice.js"></script>
<div style="position:absolute; left:200px;"> <div id="dice1"></div></div>
<br /> <br /> <br />
<div style="position:absolute; left:179px;">
<button id="throw1">Roll dice</button> </div>
* This part works. I can roll the dice and it shows a value. Now, I want to store the result.
4- In another block I write, a text question: This is the result: ${e://Field/result_matrix_embedded}
And it doesn't show anything!. The result is not stored in the field. Qualtrics.SurveyEngine.setEmbeddedData() seems to be not working.
I tried many other JavaScript codes to roll a dice, but I never manage to store the result. If you happen to know any other way rather than this code, it would be highly appreciated!
Thank you!
Best answer by Ali5
View original