Script 1
Qualtrics.SurveyEngine.addOnload(function()
{
if ($('NextButton'))
$('NextButton').hide();
if ($('PreviousButton'))
$('PreviousButton').hide();
var that = this;
Event.observe(document,'keydown',function(e){
var choiceID = null;
if (e.keyCode == 76) //'l' was pressed
{
choiceID = 1;
}
else if (e.keyCode == 72) //'h' was pressed
{
choiceID = 2;
}
if (choiceID)
{
that.setChoiceValue(choiceID,true);
that.clickNextButton();
}
});
});
Script 2
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 72: // 'h' was pressed
choiceID = 1;
break;
case 76: // 'l' was pressed
choiceID = 2;
break;
}
if (choiceID) {
Qualtrics.SurveyEngine.setEmbeddedData("choiceID",choiceID);
Event.stopObserving(document, 'keydown', keydownCallback);
that.setChoiceValue(choiceID, true);
that.clickNextButton();
}
});
});
Script 3
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;
}
if (choiceID) {
Event.stopObserving(document, 'keydown', keydownCallback);
that.setChoiceValue(choiceID, true);
that.clickNextButton();
}
});
});
Thank you for your latest response. Unfortunately, also the scripts mentioned in the links in your response does not register responses (the second link does not even let me proceed to the next page). I'm still struggling with this puzzle, any help is appreciated.
You need to change the key mappings though. Your browser listens for key presses and there is a numeric code associated with each key, as shown here: http://keycode.info/
Working Example: https://qualtricssfi.az1.qualtrics.com/jfe/preview/SV_6KzTr6Nr0UfPJSl?Q_SurveyVersionID=current&Q_CHL=preview
.qsf attached -- and as Lauren pointed out, in Preview you do have to click the survey for it to register clicks. This is because it is iFramed in rather than presented as the main scope.
Hi all,
I'm clearly a bit late to the party.
mattyb513 i'm using the code you offered in the above thread, changing the arrow up/down keys for the keys V, B and N.
I would like participants to respond v, b, or n, which are associated with a different answer. I've edited the code (below) to add an additional key. Is this correct?
I'm also wondering if there is a way to apply this code to multiple blocks at once (rather than going into each and inserting the code)?
TIA,
Hannah
Qualtrics.SurveyEngine.addOnload(function() {
var qid = this.questionId;
document.onkeyV = function(event) {
console.log('keyV',event);
if (event.which == 86) {
event.preventDefault();
Qualtrics.SurveyEngine.registryqid].setChoiceValue(1, true);
jQuery('#NextButton').click();
} else if (event.which == 78) {
event.preventDefault();
Qualtrics.SurveyEngine.registryrqid].setChoiceValue(2, true);
jQuery('#NextButton').click();
} else if (event.which == 66) {
event.preventDefault();
Qualtrics.SurveyEngine.registry6qid].setChoiceValue(3, true);
jQuery('#NextButton').click();
}
}
});
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.