Force respondent to click all 3 thumbnails before advancing | Experience Community
Skip to main content
Solved

Force respondent to click all 3 thumbnails before advancing

  • May 4, 2026
  • 6 replies
  • 42 views

Forum|alt.badge.img+6

I have three thumbnails that will display a full-size version of the images when clicked. What I want to do is force the respondent to see the 3 full-size versions of the images before advancing to the next question. Is this possible? They are currently set up as a Text/Graphic question type. 

Best answer by kgillis

on the question go into rich content editor then html source. wrap each thumbnail link with Wrap each thumbnail link with class="lightbox-img" and data-img="1" (2, 3 for the others)

Then add the below JS to the question:

Qualtrics.SurveyEngine.addOnload(function() {
  var viewed = {};
  var totalImages = 3;
  var nextBtn = document.getElementById('NextButton');

  // Disable Next button initially
  nextBtn.disabled = true;
  nextBtn.style.opacity = '0.4';
  nextBtn.title = 'Please view all images before continuing.';

  // Add status message above Next button
  var msg = document.createElement('p');
  msg.id = 'img-status';
  msg.style.color = '#c0392b';
  msg.style.fontWeight = 'bold';
  msg.style.marginBottom = '10px';
  msg.innerHTML = 'Please view all 3 images before continuing. (0 of 3 viewed)';
  nextBtn.parentNode.insertBefore(msg, nextBtn);

  function updateStatus() {
    var count = Object.keys(viewed).length;
    var statusMsg = document.getElementById('img-status');

    if (count >= totalImages) {
      statusMsg.style.color = '#27ae60';
      statusMsg.innerHTML = '✓ All images viewed — you may continue!';
      nextBtn.disabled = false;
      nextBtn.style.opacity = '1';
      nextBtn.title = '';
    } else {
      statusMsg.innerHTML = 'Please view all 3 images before continuing. (' + count + ' of 3 viewed)';
    }
  }

  // Attach click listeners to all lightbox links
  var links = document.querySelectorAll('.lightbox-img');

  links.forEach(function(link) {
    link.addEventListener('click', function() {
      var imgId = this.getAttribute('data-img');
      viewed[imgId] = true;
      updateStatus();
    });
  });
});

6 replies

kgillis
Level 6 ●●●●●●
Forum|alt.badge.img+32
  • Level 6 ●●●●●●
  • Answer
  • May 4, 2026

on the question go into rich content editor then html source. wrap each thumbnail link with Wrap each thumbnail link with class="lightbox-img" and data-img="1" (2, 3 for the others)

Then add the below JS to the question:

Qualtrics.SurveyEngine.addOnload(function() {
  var viewed = {};
  var totalImages = 3;
  var nextBtn = document.getElementById('NextButton');

  // Disable Next button initially
  nextBtn.disabled = true;
  nextBtn.style.opacity = '0.4';
  nextBtn.title = 'Please view all images before continuing.';

  // Add status message above Next button
  var msg = document.createElement('p');
  msg.id = 'img-status';
  msg.style.color = '#c0392b';
  msg.style.fontWeight = 'bold';
  msg.style.marginBottom = '10px';
  msg.innerHTML = 'Please view all 3 images before continuing. (0 of 3 viewed)';
  nextBtn.parentNode.insertBefore(msg, nextBtn);

  function updateStatus() {
    var count = Object.keys(viewed).length;
    var statusMsg = document.getElementById('img-status');

    if (count >= totalImages) {
      statusMsg.style.color = '#27ae60';
      statusMsg.innerHTML = '✓ All images viewed — you may continue!';
      nextBtn.disabled = false;
      nextBtn.style.opacity = '1';
      nextBtn.title = '';
    } else {
      statusMsg.innerHTML = 'Please view all 3 images before continuing. (' + count + ' of 3 viewed)';
    }
  }

  // Attach click listeners to all lightbox links
  var links = document.querySelectorAll('.lightbox-img');

  links.forEach(function(link) {
    link.addEventListener('click', function() {
      var imgId = this.getAttribute('data-img');
      viewed[imgId] = true;
      updateStatus();
    });
  });
});


Forum|alt.badge.img+6
  • Author
  • Level 2 ●●
  • May 5, 2026

Thanks! We are almost there. When you mentioned to ‘wrap’ each thumbnail link, this is what I did.

<a href="full image link" target="_blank">
<div class="lightbox-img" data-img="1"> <img src="thumbnail image link" alt="Email 1" width="150"></div>
</a>

The Javascript code keeps track of all my clicks, however, I can still click the next button even if it is grayed out.


vgayraud
QPN Level 7 ●●●●●●●
Forum|alt.badge.img+64
  • QPN Level 7 ●●●●●●●
  • May 5, 2026

There are native methods in the JS Question API to do that.

this.disableNextButton();
this.enableNextButton();

 


Forum|alt.badge.img+6
  • Author
  • Level 2 ●●
  • May 5, 2026
Qualtrics.SurveyEngine.addOnload(function()
{
var viewed = {};
var totalImages = 3;
var nextBtn = document.getElementById('NextButton');

// Disable Next button initially
this.disableNextButton();

// Add status message above Next button
var msg = document.createElement('p');
msg.id = 'img-status';
msg.style.color = '#c0392b';
msg.style.fontWeight = 'bold';
msg.style.marginBottom = '10px';
msg.innerHTML = 'Please take a moment to read all of the emails before continuing with the survey. (0 of 3 viewed)';
nextBtn.parentNode.insertBefore(msg, nextBtn);

function updateStatus() {
var count = Object.keys(viewed).length;
var statusMsg = document.getElementById('img-status');

if (count >= totalImages) {
statusMsg.style.color = '#27ae60';
statusMsg.innerHTML = '✓ All images viewed — you may continue!';
this.enableNextButton();
} else {
statusMsg.innerHTML = 'Please take a moment to read all of the emails before continuing with the survey. (' + count + ' of 3 viewed)';
}
}

// Attach click listeners to all lightbox links
var links = document.querySelectorAll('.lightbox-img');

links.forEach(function(link) {
link.addEventListener('click', function() {
var imgId = this.getAttribute('data-img');
viewed[imgId] = true;
updateStatus();
});
});
});

So here’s the code. It works but there is a big delay before the Next button is enabled. I monitored two tests and it took 14 and 22 seconds respectively after the message below was displayed before the Next button is enabled.

Btw, I’m using a preview link to test it. 

  


vgayraud
QPN Level 7 ●●●●●●●
Forum|alt.badge.img+64
  • QPN Level 7 ●●●●●●●
  • May 5, 2026

You cannot use this in updateStatus(), its context has shifted. Declare that = this; at the top and use that.enableNextButton();


Forum|alt.badge.img+6
  • Author
  • Level 2 ●●
  • May 5, 2026

Thanks ​@vgayraud and ​@kgillis!