0

I have around 1000+images and I want to perform the randomization over these images on Qualtrics such that only one image appears whenever someone takes survey. Could anybody guide me through this as I do not have any background in Java script.

I have prepared the following code, this code consist of image id's in an array. The function random generates a random number based on the total number of image id's in the array. This number would use to select one image out of the array. Then this image would be appended with the web link. However, am not sure the logic of this code is correct or not. It would be helpful if somebody could take look at this, as I am new to java scripting

Qualtrics.SurveyEngine.addOnload(function()

{var currentQuestionID = this.getQuestionInfo().QuestionID;

 var arr1=[IM_agGu9Te6eP0pjN3,IM_79ZbXlCrr1iRXNz,IM_2i5fyTch,IM_5uxw4IrD0TMupmt,IM_5dNoMSOmYDRVBOJ]

function randomImage() 

{
    var idx = Math.floor(Math.random()*MAX_PLUS_ONE);

    return images[idx];
};

var image1 = randomImage();

image1.style.display = 'https://az1.qualtrics.com/ControlPanel/Graphic.php?IM= 'imgae1
T. Gibbons
  • 4,919
  • 2
  • 15
  • 32

1 Answers1

0

Since you don't have any background in JavaScript, you can avoid it by using the Qualtrics Randomizer in the survey flow:

Randomizer (select one of the following, evenly distribute)
- Embedded data block: image = image1url
- Embedded data block: image = image2url
- Embedded data block: image = image3url
- etc.
T. Gibbons
  • 4,919
  • 2
  • 15
  • 32
  • Does that means I have to create the block for all the 1000+ images. I have the commands from this http://stackoverflow.com/questions/23811793/randomization-in-qualtrics-using-photos-or-graphics-and-loop-and-merge – yogesh bhandari Apr 07 '17 at 19:45
  • The question you referred to was talking about a question block, not an embedded data block. They are completely different things. You could quickly duplicate embedded data blocks and change the assigned value. You haven't told us anything about your survey. As an alternative, if all your questions that include the image are in one question block, you could make it a loop & merge block, paste the all the imageurls into a loop/merge field, then randomize the loop order and present only 1 loop. – T. Gibbons Apr 07 '17 at 20:29
  • Also, the web scraping code in that post is completely unnecessary...you can get a list of Qualtrics IDs by going Account Settings/Qualtrics ID/Library and just copy and paste the image ids. – T. Gibbons Apr 07 '17 at 20:31
  • I am using the the Image ID's from the Account Setting as you have stated. But that Image Id's are not in the form of URL. As well as Image id's being display are able to pull the image when I am copying the id in chrome. Here is the link to my survey. https://qtrial2017q1az1.az1.qualtrics.com/jfe/form/SV_a05eZQJr9l73prv – yogesh bhandari Apr 07 '17 at 21:57
  • Thank you @T.Gibbons I found the way and how to append the image in the URL. And your comment on one of following thread was quite helpful. http://stackoverflow.com/questions/42470395/how-to-loop-over-hundreds-of-images-in-qulatrics-help-needed-to-implement-code/42493715#42493715 – yogesh bhandari Apr 07 '17 at 23:38
  • However, right now am trying to make the custom java script such that it would create an array with Image IDs and then append it with URL. And then display the image. With this I would also like to put the condition such that one imagId does not get selected for more than 5 times. What are the commands in API that would be helpful to me. Thank you for your comments. – yogesh bhandari Apr 07 '17 at 23:43
  • No command in the Qualtrics API would help you with that. Also, you can't control how many times an image gets selected using JavaScript (it doesn't know about other responses)...a reason to use the Randomizer with evenly distribute. If you've written code, edit your post and add it. – T. Gibbons Apr 08 '17 at 14:48
  • @T Gibbons, I posted the code in my post. It would be helpful if you could take look at the code and suggest some corrections. – yogesh bhandari Apr 12 '17 at 21:14