Display text one sentence at a time/Key press use in display logic | XM Community
Skip to main content

Hello, 

I am new to using Javascript in Qualtrics. I have a paragraph of text (about 4 sentences long) that I want the user to read and I was wondering if there was a way to display the paragraph one sentence at a time (advance using a key press, f.e. spacebar). If there is an easy way to do this that would be great however the way I have been trying to do it is to have each sentence be its own text question and to display the next text question on a key press. The problem I am having is that I can’t seem to find a way to add a key press into the display logic of a question. 

TLDR: How can I add a keypress to the display logic of a question. 

Thank you,

H

Instead of key press why don’t you use click function to show the paragraphs on click and can work for both browser and mobile devices.


Hello, 

I am new to using Javascript in Qualtrics. I have a paragraph of text (about 4 sentences long) that I want the user to read and I was wondering if there was a way to display the paragraph one sentence at a time (advance using a key press, f.e. spacebar). If there is an easy way to do this that would be great however the way I have been trying to do it is to have each sentence be its own text question and to display the next text question on a key press. The problem I am having is that I can’t seem to find a way to add a key press into the display logic of a question. 

TLDR: How can I add a keypress to the display logic of a question. 

Thank you,

H

Why do you need display logic? They gonna read all 4 of them anyway. In my understanding, you’re trying to map the keypress with next button, right? Add this code to the paragraph JavaScript and it will help

Qualtrics.SurveyEngine.addOnReady(function()
{
var that = this;
Event.observe(document, 'keydown', function keydownCallback(e) {
switch (e.keyCode) {
case 32: // 'spacebar'
break;
}
Event.stopObserving(document, 'keydown', keydownCallback);
that.clickNextButton();
});
});


 


Leave a Reply