Eugene Eugene -4 years ago 286
Javascript Question

Qualtrics: Pressing enter key to emulate continue button

I'm very new to JavaScript, and I'm currently trying to add a custom code to my Qualtrics survey that makes it so pressing the enter key continues the survey. I have a code that should be working; however, I'm getting an "Unexpected token )" error.

Here is the code:

Qualtrics.SurveyEngine.addOnload(function()
{
document.addEventListener("keydown", function(e) {
if (e.keyCode === 13) {

function(){
that.clickNextButton();
}

}
}

});


the "clickNextButton" function was found in the Qualtrics API document and is supposed to emulate the next button click. The function is clickNextButton(), but the example provided has the code as that.clickNextButton().

The example they use is below:

//Hides the next button and displays the question
//for 5 seconds before moving to the next page
this.hideNextButton();
var that = this;
(function(){that.clickNextButton();}).delay(5);


I don't need the hiding button function or the delay, but just wanted to include an example of how it is used.

Any help is much appreciated, thanks in advance!

Answer Source

Here is a simplified version that works (updated to hide NextButton):

Qualtrics.SurveyEngine.addOnload(function()  {
    $('NextButton').hide();         
    document.on("keydown", function(e) {
         if (e.keyCode === 13) $('NextButton').click();
    });
});
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download