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

I'm trying to code the left and right arrow keys to be yes/no answer keys and report that result

  • 23 August 2023
  • 2 replies
  • 38 views

Userlevel 1
Badge +1

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.registry[qid].setChoiceValue(1, true);
            jQuery('#NextButton').click();
              `Qualtrics.SurveyEngine.setEmbeddedData('F64', 1);`
        } else if (event.which == 39) {
            event.preventDefault();
            Qualtrics.SurveyEngine.registry[qid].setChoiceValue(2, true);
                 `Qualtrics.SurveyEngine.setEmbeddedData('F64', 2);`
                      jQuery('#NextButton').click();

 

This is my work flow incase this is the problem:

 

icon

Best answer by TomG 23 August 2023, 15:03

View original

2 replies

Userlevel 7
Badge +27

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();
...

 

Userlevel 1
Badge +1

TomG,

 

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

 

Ralph

Leave a Reply