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

Display text one sentence at a time/Key press use in display logic

  • September 21, 2023
  • 2 replies
  • 263 views

Forum|alt.badge.img+1

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

Best answer by Nam Nguyen

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();
});
});


 

2 replies

rgupta15
Level 4 ●●●●
Forum|alt.badge.img+8
  • Level 4 ●●●●
  • 92 replies
  • September 22, 2023

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.


Nam Nguyen
QPN Level 8 ●●●●●●●●
Forum|alt.badge.img+29
  • QPN Level 8 ●●●●●●●●
  • 1096 replies
  • Answer
  • September 22, 2023

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();
});
});