How to count the number of time a participant push a key ? | XM Community
Solved

How to count the number of time a participant push a key ?

  • 15 June 2020
  • 6 replies
  • 12 views

Hi everyone,
I'm new on this forum.
I'm here because i try to record the number of time a participant press a key when a text is displayed on the screen. So i try to adapt a script i fund here to build this function (my only training in programmation is a 20 hours tuto on openclassroom...). I add the script in the question (in fact in the descriptive text). Here is my attempt :
Qualtrics.SurveyEngine.addOnReady(function() {                                          
 let questionId = "NumberOfPushG" ;                                                    
 document.onkeydown = function(event) {                                                
  let i = 0                                                                            
   if (event.which == 71){                                                             
     event.preventDefault();                                                           
     i += 1                                                                            
     Qualtrics.SurveyEngine.registry[questionId].setChoiceValue(i);                    
       }
   }
});
Of course it doesn't work i would not be here otherwise... 😥
What am i doing wrong ?
Thank you in advance to everyone.

icon

Best answer by TomG 15 June 2020, 17:38

View original

6 replies

Userlevel 7
Badge +27

You have a number of logic and syntax errors. For starters, NumberofPushG isn't a valid questionId. Also, you can't set a value for a Descriptive Text question.
Try:
Qualtrics.SurveyEngine.addOnReady(function() {                                          
 var i = 0;                                                 
 document.onkeydown = function(event) {                                                
if(event.which == 71){                                                             
     event.preventDefault();                                                           
     i++;                                                                            
     Qualtrics.SurveyEngine.setEmbeddedData("count",i);                    
   }
 }
});

Thank you for your answer ! If i can't set a value for a Descriptive Text, i have to put this in a question under the text ? what kind ? (sorry if it's a dumb question ...).

I tried it in a descriptive text, it does not actually work. But I tried in a multiple choice question and a text input question, it doesn't work either.

Userlevel 7
Badge +27

https://www.qualtrics.com/community/discussion/comment/26753#Comment_26753I changed it to setEmbeddedData so it would work with a Descriptive Text question. Be sure the define "count" in the survey flow so it gets saved in your response data.

https://www.qualtrics.com/community/discussion/comment/26755#Comment_26755I'm trying to do it, i'll be back with a victory.

Hum, ok i need more help, the "survey flow" is that the thing ?
image.pngSo, i try to add an embedded data, i suppose it's a block " Embedded data" but where can i find how to define " count "
image.pngIs it here ?




Ok, it does work ! Thank you so much !

Leave a Reply