Trying to update embedded data field with custom javascript | XM Community
Solved

Trying to update embedded data field with custom javascript

  • 12 September 2020
  • 2 replies
  • 151 views

Hi,
Hoping someone can tell me what I'm doing wrong. I'm trying to use JavaScript to update an embedded data field.
My survey consists of a series of questions containing an audio clip which the respondents click to play and then answer the question. I want to count how many times they play the audio before moving on to the next question.
HTML


JavaScript
Qualtrics.SurveyEngine.addOnReady(function()
{
/*Place your JavaScript here to run when the page is fully displayed*/

var playCount = 0;
function incrPlayCount(){
playCount++;
};

document.getElementById('audioElm').addEventListener('play', incrPlayCount);

Qualtrics.SurveyEngine.addOnPageSubmit(function(type)
{
if(type == "next")
{
Qualtrics.SurveyEngine.setEmbeddedData("PlayCountQ1", playCount);
}
});

});

Survey Flow
Screen Shot 2020-09-12 at 4.34.24 pm.png
New to Qualtrics and Javascript so any advice appreciated!

icon

Best answer by rondev 12 September 2020, 14:01

View original

2 replies

Userlevel 7
Badge +22

Try changing the code to as below:
var playCount = 0;
Qualtrics.SurveyEngine.addOnReady(function()
{
/*Place your JavaScript here to run when the page is fully displayed*/


function incrPlayCount(){
playCount++;
};

document.getElementById('audioElm').addEventListener('play', incrPlayCount);



});

Qualtrics.SurveyEngine.addOnPageSubmit(function(type)
{
if(type == "next")
{
Qualtrics.SurveyEngine.setEmbeddedData("PlayCountQ1", playCount);
}
});

Ok I just realised that it is working... I was just looking for the data in the wrong place to the whole time 😑
Nothing shows up on the 'data' page but it does show up when I export the data.
Thanks for the help though!

Leave a Reply