I have built a simple experiment that requires participants to make a judgement on a photograph. They press on of three buttons (J, K or L) and the page moves on to the next photograph. I use the following code to advance the page with the keys and hide the submission button.
However, Qualtrics is not recording the key pressed as a response/answer (J, K or L). The questions are multiple choice questions. Is there a simple mistake anybody else can see in this code or in the questions that i cannot see?
Do i need to code values within the answers? Please help!
Qualtrics.SurveyEngine.addOnload(function()
{
this.hideNextButton();
this.hidePreviousButton();
var that = this;
Event.observe(document, 'keydown', function keydownCallback(e) {
var choiceID = null;
switch (e.keyCode) {
case 74: // 'J' was pressed
choiceID = 1;
break;
case 75: // 'K' was pressed
choiceID = 2;
break;
case 76: // 'L' was pressed
choiceID = 3;
break;
}
if (choiceID) {
Event.stopObserving(document, 'keydown', keydownCallback);
that.setChoiceValue(choiceID, true);
that.clickNextButton();
}
});
});
Your code looks fine. Have you tried it on a different browser? Some browsers (such as Opera) return somewhat different codes.
Thank you for your reply!
I am currently using Chrome and have attempted Safari also. The data exports as follows. I will have another fiddle with it and feedback if i am able to change anything. (This is only on desktop).
Any ideas would be appreciated though!
I tried it, and its working for me. So, I couldn't replicate your problem. Is the page moving forward? If yes, then along with the choice ID, try storing the result as an embedded data also, at least you'll be able to capture the data you require.
Hi thanks for testing it for me. I have created another block within a new project and you're correct, the code is functional. I think for now, I will re-make the whole block as this seems the best way to make sure it is fully functional.
Thank you for your help! I have no idea what has happened.
Okay...I figured out the problem. What happens is that sometimes the choice values aren't set sequentially. This happens when you've made some changes to the choices. Even though, I'm not certain when it does.
If you change
that.setChoiceValue(choiceID, true)to
that.setChoiceValue(that.getChoices()[choiceID-1], true).It should work.
I'm very late to this, but I'm hoping I can still ask a question about the code.
I'm designing a similar experiment. I would like participants to respond in this same way, but instead of the page advancing after they respond, I have a timing question such that the item remains on the screen for a few seconds (even if the participant responds).
Which component of this code is associated with advancing the page? I will use the code without this component.
TIA, Hannah
Delete this:
that.clickNextButton();
If you want, you can also put it into a setTimeOut block to be executed after sometime.
Thanks ahmedA. I've tried this, but it hasn't worked.
Each question is presented in a different block, each block contains a picture, a multiple choice question, and a timing question. Under which question should I place this code?
Thanks for your help!
All of them.
Thanks!
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.