Solved
Passing question metadata from one question into javascript in another question without hardcoding
I'm completely new here...
Question X in a question block has a list of answers (not the values for a respondent, the actual text in the answers).
Question X+1 in the block has some javascript that uses those answers to do some stuff.
The question block is intended to be copied and re-used across surveys (so I don't want to hard code the question ID anywhere)
It looks like there are two ways to do this:
1) Set/Get embedded data.
I can pass the QID from question X into the value, and then retrieve it in question X+1, however, I'm messing up the syntax to reference the answer text in the prior question...
var myQID = Qualtrics.SurveyEngine.getEmbeddedData("myQuestionID")
var myAnswerArray = jquery("#"+myQID).getAnswers()
2) Initialize field names in the header, and write functions to update/retrieve them from the global variables defined in the header. I'm slightly concerned that this makes re-using the question block less monkey simple, but maybe it's the better approach?
Any thoughts on which is the better approach, and my broken syntax above?
['newbie' is a kind word for me, btw]
Best answer by TomG
> @KevinK said:
> 1) The sole purpose is to set up Question 3. And actually, this is a generalization, we will probably have Q1, Q2, Q3, Q4 to populate the content to set up Q5.
> 2) Multiple choice questions, yep. Think of it as items to populate an array variable. We might put some images in too, in addition to the text, but mostly just text.
> 3) Question 3 (really question 5) is totally custom javascript (not yet built), and we don't know what it will exactly look like yet - for example, an interactive multidimensional visualization. Whatever it is, it will be totally encapsulated (and we'll send the content as inputs). But the person configuring the inputs would have no coding skill (e.g. a social science undergraduate).
>
> I hope all of that makes sense.
Put all the questions on the same page, hide the setup questions with JavaScript, and use JavaScript to traverse the page to gather the input data you need. For example, to create an array with the choice labels from the first question on the page:
```
var setupQs = jQuery("#"+this.questionId).prevAll("div.QuestionOuter");
var q1choices = [];
setupQs.eq(0).find("label.SingleAnswer > span").each(function() {
q1choices.push(jQuery(this).html());
});
console.log(q1choices);
```
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.
