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

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

  • Sep 21, 2023 8:15 PM UTC
  • 2 replies
  • 339 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();
});
});


 

View original

2 replies

rgupta15
Level 4 ●●●●
Forum|alt.badge.img+8
  • Level 4 ●●●●
  • Sep 22, 2023 12:19 AM UTC

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 ●●●●●●●●
  • Answer
  • Sep 22, 2023 3:19 AM UTC

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