Javascript sometimes fails to replace image without refresh | XM Community
Skip to main content

I am using Javascript to replace images in a series of matrix table questions, following the procedure described here.
For some of the questions, the images are not being replaced when the page initially loads. If I click the "next" button, causing Qualtrics to prompt me to answer the question, the image will then consistently be replaced. This makes me suspect that the Javascript is executing before there is an image to be replaced or that I am experiencing a redraw problem as reported here.
Is there a way to more consistently replace images or to trigger the same refresh that is being done when Qualtrics prompts for the question to be answered?
Javascript (same results if I put it in the OnLoad or OnReady sections):
var count = Number("${e://Field/count}"); 
var files = Qualtrics.SurveyEngine.getEmbeddedData('block_all');
file = filesscount]
path = "https://sipacolumbia.co1.qualtrics.com/ControlPanel/Graphic.php?IM=" + file ;
var img = document.getElementById("imgdir");
img.src = path;
Qualtrics.SurveyEngine.setEmbeddedData("count", count + 1);

Question html (before replacement of image url):




You can use embedded variables and store your images in it and show it based on counter variable via js or the same can be done with loop and merge with a hidden question for the loop.


Leave a Reply