Dynamically get each question's choice text entry value using javascript? | XM Community
Skip to main content

Hi everyone!
I have a loop and merge where respondents input 20 numbers - 1 per round. I want to create a summary table at the end where I show 2 columns: one column with each of the respondent's 20 numbers and another column with the correct 20 numbers. To do this, I need to be able to dynamically get each of the input responses from the loop and merge in a for loop.
Here's what I currently have:
correct_nums = Qualtrics.SurveyEngine.getEmbeddedData( 'correct_vals' );

for(let i=1; i <21; i++) {
curr_correctnum = correct_nums.split(",")[i].toString();

//this line currently does not work
curr_yourforecast = "${q://" + i.toString() + "_QID3/ChoiceTextEntryValue}";
//this line works - but i need to dynamically replace the 1 in front
console.log("${q://1_QID3/ChoiceTextEntryValue}")

var tableRef = document.getElementById('summary_table1').getElementsByTagName('tbody')[0];
var newRow = tableRef.insertRow(tableRef.rows.length);
var myHtmlContent = "" + curr_correctnum + "" + curr_yourforecast "";
newRow.innerHTML = myHtmlContent;
}

My issue is that I am not able to dynamically access different choice text entry values for each of the loop and merge rounds. Does anyone know a good way to do this?
Thanks so much!

You don't need JS. Look at the Piped text options for loop and merge.


Leave a Reply