Hello, Javascript Newbie here!
I am programming an experiment where people see stimuli and have to decide if they are the same or different - and for this they press 1 and 2, respectively. Participants see the stimuli for a set of time and then are presented a multiple choice with the two options; I specifically want them to use the keys, instead of just using the mouse. I want the next trial to start whenever one of the two keys is pressed. In the end, I want the database to have their answers recorded - that is what I am struggling with! The field for the answers always comes out empty.
Through foruns here and there, I put together the following code. Can you help me out? What should I change so that when I download the data I can see whether participants pressed 1 or 2?
Qualtrics.SurveyEngine.addOnload(function()
{
this.hideNextButton(); //Blocks from advancing
this.hidePreviousButton(); //Blocks from retreating
var that = this;
Event.observe(document, 'keydown', function keydownCallback(e) { //Set values for keys
var choiceID = null;
switch (e.keyCode) {
case 49: // '1' was pressed
choiceID = 1;
}
switch (e.keyCode) {
case 50: // '2' was pressed
choiceID = 2;
}
if (choiceID) {
Event.stopObserving(document, 'keydown', keydownCallback);
that.setChoiceValue(choiceID, true);
that.clickNextButton();
} //Advance when key are pressed
});
});
Autoadvance and Record Key Pressed
Best answer by fcruz27
Thank you, Ahmed!
I was about to come here and share the answer with whoever might be facing the same issue - I found the answer later yesterday
When I created a new question, it worked fine - the issue was with the choiceIDs: if you have, for example, two options the choiceIDs will be 1 and 2, respectively; imagine that you add another option (choiceID = 3) and then delete one of the former (choiceID = 1) - you will be left with 2 and 3. If your code registers 1 and 2,if anyone answer 1 the answer won't be recorded!
So, everyone make sure the choiceID that you set your value into is the same assigned to the options you have there.
Sign up
Already have an account? Login
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join.
No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Login with Qualtrics
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join. No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Login to the Community
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join.
No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Login with Qualtrics
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join. No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.
