Key Press Response Issue | XM Community
Solved

Key Press Response Issue

  • 3 August 2018
  • 3 replies
  • 42 views

Hello! I'm trying to add java script to descriptive text questions so that participants can press one of two keys (1 or 0) and the survey will automatically progress to the next question and the key that they pressed (1 or 0) is reported in the exported data file.

With my current script (image attached) I have found that pressing 1 or 0 does move the participant to the next question (yay!) However, I'm having trouble with the exported data. Originally, the questions that I added script to (Q3 and Q6) were both descriptive text questions. In this data file, there was no column for Q3 or Q6. Then, I tried changing Q3 to a multiple choice question and retaking the survey. In this data file, there was still no column for Q6, but there was a column for Q3. However, there was only Q3 data recorded for the 3 previous attempts (in which Q3 was a descriptive text question) and there was no Q3 data for the most recent attempt (in which Q3 was a multiple choice question). (I have attached these 2 data files-- note: I've deleted the name, location, IP address etc.)

So it seems that, when java script is added to descriptive text questions, the data is being recorded, but it is not being reported in the exported data file. Does anyone know how to set it up so that the key (1 or 0) that is pressed in response to a descriptive text question is recorded and reported?

I based my script off to a response on this thread. Community user @mattyb513 posted their code here and I got the event.which numbers and event.code for 1 and 0 here.

!
icon

Best answer by mattyb513 3 August 2018, 18:55

View original

3 replies

Userlevel 6
Badge +6
It's probably easiest to leave it as a descriptive text and then just record the response with embedded data.

You can replace the `Qualtrics.SurveyEngine.registry[qid]...` lines with `Qualtrics.SurveyEngine.setEmbeddedData('MyEmbeddedDataName','0');` and `Qualtrics.SurveyEngine.setEmbeddedData('MyEmbeddedDataName','1');`

Of course, replace `MyEmbeddedDataName` with whatever you want the Embedded Data to be named.

Then in your survey flow, anywhere in it, add an EmbeddedData block and name it the same thing. Don't set a value. This will force it to show in your export.
We had some issues with the embedded data approach. Specifically, we only got one embedded data column in our exported data file--it only reported the participant's last response. (see Embedded Data Output attachment-- note: I've deleted the name, location, IP address etc.)

Here is the solution we found:
Each block includes a timing question, and image, a page break, and a multiple choice question. The multiple choice question for every block asks "Same or different?" and the first choice is always "same" and the second choice is always "different."

Current script:
Qualtrics.SurveyEngine.addOnReady(function(){

jQuery('body').keydown( function( event ) {

    switch (event.which) {
        case 49: // the 1 key
            event.preventDefault();
            jQuery(jQuery('span.LabelWrapper label')[0]).click()
            jQuery('#NextButton').click();
            break;
        case 48: // the 0 key
            event.preventDefault();
            jQuery(jQuery('span.LabelWrapper label')[1]).click()
            jQuery('#NextButton').click();
            break;
    
        default:
            // don't do anything
            break;
    }

});

A keypress of the 1 corresponds to the first multiple choice option (same) and a keypress of the 0 key corresponds to the second multiple choice option (different). Therefore, when a participant presses "1," "same" is recorded for the question and the survey automatically progresses. Similarly, when a participant presses "2," "different" is recorded for the question and the survey automatically progresses. (see Output attached-- note: I've deleted the name, location, IP address etc.)

In addition, we want all of our participants to respond through pressing 1 or 0 rather than clicking either of the multiple choice options. Therefore, we selected Look and Feel > Advanced > + Add Custom CSS. We added: `span.LabelWrapper label { display: none !important; }` As a result, the multiple choice options are not displayed to participants. Rather, they only see "same or different?"

This is all working perfectly which is great! We do have one more question: Our goal is to capture the response distinctly for each multiple choice question (each multiple choice question is in a separate block). Therefore, we need to run our Java script on every multiple choice question and we will have 300 multiple choice questions. Is there a way to apply our script to every multiple choice question without copy and pasting it into each individual question?

Thanks for helping us work through this!
@anm54267 To answer your final question: have you looked into the loop & merge options of a block to do the repetitions?

Leave a Reply