Count the number of Keystrokes | XM Community
Skip to main content
Solved

Count the number of Keystrokes


Forum|alt.badge.img+1

Hi all,
I have an essay question in a Qualtrics survey and want to be able to record--unbeknownst to respondents--the total number of keystrokes (ideally as embedded data) used to type into the text box.
I want to know, for instance, if someone typed in "hello" whether they typed that word (

keystrokes
= 5) or if they copy>pasted "hello" (
keystrokes
= 1 or 2). In fact, if someone wrote "hellos" then deleted the "s", I'd want that recorded too (
keystrokes
= 7). Does anyone know if this is possible?
Similarly, is there code that will automatically count the number of characters (so that anyone who writes "hello" would get a score of
characters
= 5 whether they copy>pasted, typed it perfectly, or had a typo that they corrected)?
Thanks!

Best answer by rondev

Create two ED(CharacterCount, KeyStrokeCount ) at the beginning of survey flow and then paste below code in the JS of Essay question

var k =0;
var that = this;
jQuery("#"+ that.questionId+" .InputText ").on('keyup',function(){
k++;
});
jQuery("#NextButton").on('click',function(){
  Qualtrics.SurveyEngine.setEmbeddedData("KeyStrokeCount", k);
  Qualtrics.SurveyEngine.setEmbeddedData("CharacterCount", jQuery("#"+ that.questionId+" .InputText ").val().replace(/ /g,'').length);
  });

View original

4 replies

rondev
Level 6 ●●●●●●
Forum|alt.badge.img+22
  • Level 6 ●●●●●●
  • 1449 replies
  • May 4, 2020

Yes, for the first scenario you can have keydown event on .InputText and increment a counter in it.
Then, on click of NextButton you can set a ED with that counter value. Similarly for second scenario you can check the length of only character using regex and set it's value in another ED.


Forum|alt.badge.img+1
  • Author
  • 32 replies
  • May 4, 2020

Hi rondev ,
Thanks for this quick response! I'm afraid I'm new to JS and don't have the skills to implement your proposed solutions (either the .InputText or the length-checker), or to save them as ED on the click of NextButton.
I tried hunting around the Qualtrics Community for relevant posts but couldn't find any. Do you know where code of this sort exists?
You're the best!

FWIW, HERE is the closest I've found.


rondev
Level 6 ●●●●●●
Forum|alt.badge.img+22
  • Level 6 ●●●●●●
  • 1449 replies
  • Answer
  • May 4, 2020

Create two ED(CharacterCount, KeyStrokeCount ) at the beginning of survey flow and then paste below code in the JS of Essay question

var k =0;
var that = this;
jQuery("#"+ that.questionId+" .InputText ").on('keyup',function(){
k++;
});
jQuery("#NextButton").on('click',function(){
  Qualtrics.SurveyEngine.setEmbeddedData("KeyStrokeCount", k);
  Qualtrics.SurveyEngine.setEmbeddedData("CharacterCount", jQuery("#"+ that.questionId+" .InputText ").val().replace(/ /g,'').length);
  });


Forum|alt.badge.img+1
  • Author
  • 32 replies
  • May 4, 2020

rondev Thanks so much!


Leave a Reply