Use IF like function on embedded values | XM Community
Skip to main content
Dear community,



I am designing a survey in which respondents first select an answer from a list of 13 possible answers. Then, they again select answer from the same list (-1) of now 12 possible answers. Then the answers to both questions are used to generate content later in the survey. Using embedded values i have figured out how to transfer the answers to the two question to questions later:



party1 = ${q://QID32/ChoiceDescription/1}

party2 = ${q://QID34/ChoiceDescription/x2}



So later, I refer to $e://Field/party1, etc. And this works. In addition to this I also need to display specific images, that relate to these party1, party2 labels. How do I refer to this? I was thinking of doing something like:



pic1 = paste(party1, ".jpg")



But I do not know javascript at all. And also I do not know how to refer to images loaded into the qualtrics library.



Please do note that I have 256 different possible combinations of the first two questions, and I do not want to use branching logic for this.



Thank you.
Hi @Gijs,

you can refer to an image from the Qualtrics library using its URL in HTML editing mode of the question in the same way as you refer to any other image in HTML.



I don't know about a way which would enable you to use just names of your images and not the URL and I think that an if like function would be too complicated.



I would:

1) store all your URLs in an embedded field separated by semicolons

2) get the id of your choice ("SelectedChoicesRecode") of your choice, convert it to number and use the id to index the array

3) change the src of your img HTML element (note that the HTML element must have an id)



It could look like this:



Qualtrics.SurveyEngine.addOnload(function()

{

var urls = "${e://Field/urls}".split(";");

var my_url = urls[Number("${q://QID6/SelectedChoicesRecode}")-1];

document.getElementById("imageid").src=my_url;

});



You can do almost the same also for the second party but. You just have to remove the URL which was already used at first from the array.
Thanks @fleb. It took me a few days to find the time to implement this, but it worked with some minor tweaks. Thanks!

Leave a Reply