Community Groups are officially here!
We've released Groups, a new feature that enables us to connect community members of similar industries and interests in a shared, private space. You can check out all of the details here, including information about who can join, how to join, and what Groups are currently offered. Please leave your feedback through this Community Groups Feedback Survey.

Change image in multiple choice questions after time delay (java)

Qualtricshelp
Qualtricshelp Community Member - Trial User Qubie ✭

Hello,

I want to change the graphics I included in one of the option for a multiple choice question type after certain seconds.
I wrote the following code, but it doesn't work. Does anyone has an idea how to fix it?
I want to change choice A's image to something else after 4000 milliseconds.

var delayTime2=4000;

setTimeout(function(){
    console.log(jQuery("#QID68-1-label"));
    console.log(jQuery("#QID68-1-label").find("img"));
    jQuery("#QID68-1-label").find("img").attr("src","https://iu.co1.qualtrics.com/WRQualtricsControlPanel/Graphic.php?IM=IM_8dCmD7RnfZIh4c5"); 
}, delayTime2);

});
\

Answers

  • npetrov937
    npetrov937 London, UKCommunity Member - Trial User Guru ✭✭

    First, update your option for the multiple choice question by adding an id to the image. Go to the option you want to change, then click Rich Content Editor, then add your initial graphic by selecting "Insert Graphic", then click "Source" to open the HTML and you should see something like this (values will differ):

    <img src="YOUR ORIGINAL IMG URL HERE" style="width: 1437px; height: 1301px;" />

    Add an id to the image:

    <img id="myidhere" src="YOUR ORIGINAL IMG URL HERE" style="width: 1437px; height: 1301px;" />

    Then use the following JavaScript for that question:

    var delayTime2=4000;
    
    setTimeout(function(){
        document.getElementById('myidhere').src = "NEW IMAGE URL HERE"
    }, delayTime2);
    

    Hope that helps!