I'm trying to code the left and right arrow keys to be yes/no answer keys and report that result | XM Community
Skip to main content

This is my JC code. The key codes seem to be working but no data is being reported in the file.

 

Qualtrics.SurveyEngine.addOnload(function()
{
    var qid = this.questionId;

    document.onkeydown = function(event) {
        console.log('keydown',event);
        if (event.which == 37) {
            event.preventDefault();
            Qualtrics.SurveyEngine.registryqid].setChoiceValue(1, true);
            jQuery('#NextButton').click();
              `Qualtrics.SurveyEngine.setEmbeddedData('F64', 1);`
        } else if (event.which == 39) {
            event.preventDefault();
            Qualtrics.SurveyEngine.registryvqid].setChoiceValue(2, true);
                 `Qualtrics.SurveyEngine.setEmbeddedData('F64', 2);`
                      jQuery('#NextButton').click();

 

This is my work flow incase this is the problem:

 

Qualtrics.SurveyEngine.registry[qid].setChoiceValue isn’t valid and you’ve put the setEmbeddedData lines in quotes. Also ‘which’ is deprecated, so should be avoided. Try:

Qualtrics.SurveyEngine.addOnload(function() {
var qobj = this;
document.onkeydown = function(event) {
console.log('keydown',event);
if (event.key == 'ArrowLeft') {
event.preventDefault();
qobj.setChoiceValue(1, true);
Qualtrics.SurveyEngine.setEmbeddedData('F64', 1);
qobj.clickNextButton();
} else if (event.key == 'ArrowRight') {
event.preventDefault();
qobj.setChoiceValue(2, true);
Qualtrics.SurveyEngine.setEmbeddedData('F64', 2);
qobj.clickNextButton();
...

 


TomG,

 

 Thank you so very much! It worked (as I’m sure you knew it would. You’re amazing!

 

Ralph


Leave a Reply