I made a survey with a loop/merge element. Each loop contains a single MC question. I want to get the reaction time for each question and append that to the end of an Embedded Data variable so that the end product is an array containing the reaction time for each question.
So far, the code I have is:
Qualtrics.SurveyEngine.addOnReady(function()
{
var starttime = new Date().getTime();
$('NextButton').hide();
this.questionclick = function(event,element){
if (element.type == 'radio') {
var endtime = new Date().getTime();
var RT = endtime - starttime;
var EmData = Qualtrics.SurveyEngine.getEmbeddedData('reactiontime');
let Holder = [];
Holder.push(EmData);
Holder.push(RT);
Qualtrics.SurveyEngine.setEmbeddedData('reactiontime', Holder);
$('NextButton').click();
}
}
});
This code results in something like the following:
[[{"1":4697},2943],"10392"]
where the larger numbers are the RTs. No idea where the "1" comes from. So, it works, but is a mess. I was wondering if there was a way to alter my code so that the Embedded Data ends up looking like this by the end of the survey:
[RT1, RT2, RT3...]
rather than the messy current form.
Thanks in advance for your help!
(sorry if the formatting is poor, I am new to this forum)
Page 1 / 1
The problem is you are saving an array to the embedded data field when what you want is a string. Instead you could do something like:
```
var EmData = Qualtrics.SurveyEngine.getEmbeddedData('reactiontime');
if(EmData.length > 0) EmData += ", ";
EmData += RT;
Qualtrics.SurveyEngine.setEmbeddedData('reactiontime', EmData);
```
```
var EmData = Qualtrics.SurveyEngine.getEmbeddedData('reactiontime');
if(EmData.length > 0) EmData += ", ";
EmData += RT;
Qualtrics.SurveyEngine.setEmbeddedData('reactiontime', EmData);
```
@TomG You gave me the hint I needed. Thank you for your help. For anyone else who stumbles across this, the following code will get you the RTs for a repeated MC question in a loop-merge block as a string of comma separated values:
Qualtrics.SurveyEngine.addOnReady(function()
{
var starttime = new Date().getTime();
$('NextButton').hide();
this.questionclick = function(event,element){
if (element.type == 'radio') {
var endtime = new Date().getTime();
var RT = endtime - starttime;
var EmData = Qualtrics.SurveyEngine.getEmbeddedData('reactiontime');
var Holder = [];
if (EmData == null){
Holder += RT
Qualtrics.SurveyEngine.setEmbeddedData('reactiontime', Holder);
}
if (EmData != null){
Holder += EmData;
Holder += ", ";
Holder += RT;
Qualtrics.SurveyEngine.setEmbeddedData('reactiontime', Holder);
}
$('NextButton').click();
}
}
});
Qualtrics.SurveyEngine.addOnReady(function()
{
var starttime = new Date().getTime();
$('NextButton').hide();
this.questionclick = function(event,element){
if (element.type == 'radio') {
var endtime = new Date().getTime();
var RT = endtime - starttime;
var EmData = Qualtrics.SurveyEngine.getEmbeddedData('reactiontime');
var Holder = [];
if (EmData == null){
Holder += RT
Qualtrics.SurveyEngine.setEmbeddedData('reactiontime', Holder);
}
if (EmData != null){
Holder += EmData;
Holder += ", ";
Holder += RT;
Qualtrics.SurveyEngine.setEmbeddedData('reactiontime', Holder);
}
$('NextButton').click();
}
}
});
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.