Change image based on slider using loop and merge | XM Community
Skip to main content

Hello everyone,

I am programming a question in which the image changes according to the slider's position.
My images are stored in the library, and the qualtrics IDs are correctly placed in the loop and merge fields.
However my code, inspired by Nami's , is not working with the loop and merge fields. Can any one help me figure out what I am doing wrong?
Thanks!!

Qualtrics.SurveyEngine.addOnReady(function()
  {
    /*Place your JavaScript here to run when the page is fully displayed*/   
  // Get Image
 var img = jQuery("#myImage");
    currentQID = this.questionId

    // Set default image
    imgu0].src = '${lm://Field/20}';

    // Function to look for track changes in slider
    jQuery("input type = hidden]").change(function() {
      var answer = parseInt(jQuery("#" + currentQID + " input.ResultsInput").eq(0).val());

      // Images 1-21 -- in order below
      var images_list = -
        '${lm://Field/2}',
        '${lm://Field/4}',
        '${lm://Field/6}',
        '${lm://Field/8}',
        '${lm://Field/10}',
        '${lm://Field/12}',
        '${lm://Field/14}',
        '${lm://Field/16}',
        '${lm://Field/18}',
        '${lm://Field/20}',
        '${lm://Field/22}',
        '${lm://Field/24}',
        '${lm://Field/26}',
        '${lm://Field/28}',
        '${lm://Field/30}',
        '${lm://Field/32}',
        '${lm://Field/34}',
        '${lm://Field/36}',
        '${lm://Field/38}',
        '${lm://Field/40}',
        '${lm://Field/42}',
      ]
      // Swap image according to answer (zero indexed, thus -1)
      imgi0].src = images_listanswer - 1]
    });
  });

Be the first to reply!

Leave a Reply