Hi all. I want to start out by saying that there seems to be a very similar problem to what I have but I can't figure out why it won't work for me. https://community.qualtrics.com/XMcommunity/discussion/19749/capture-and-embed-data-within-a-loop
The set up:
Block 1: Some regular questions
- Q1: How many people have you hung out with in the past two days? (dropdown 1-10)
Block 2: Loop & Merge (based on answer to Q1)
- Q2: Who have you hung out with?
- Tim
- Bob
- Joe
- New Person
- Q3: [IF "New Person" SELECTED IN Q2] What is the name of this new person? [text entry]
The goal:
Eventually, I need to set embdedded data for any new persons in the loop and merge, but for now I'm simply trying to find a way to even capture the response in javascript which seems like it should be easy.
My javascript:
Right now I have the following javascript on Q3:
Qualtrics.SurveyEngine.addOnUnload(function()
{
/*Place your JavaScript here to run when the page is unloaded*/
let text = jQuery('#QR~'+this.questionId+" input[type=text]").eq(0).val()
console.log(text)
});
I have also tried:
Qualtrics.SurveyEngine.addOnUnload(function()
{
/*Place your JavaScript here to run when the page is unloaded*/
let loopNumber = "${lm://CurrentLoopNumber}"
let qId = this.questionId
let embeddedDataFieldname = "textEntry_"
embeddedDataFieldname = embeddedDataFieldname +loopNumber
console.log('QR~'+qId)
let text = document.getElementById('QR~'+qId).value
console.log(text)
/*Qualtrics.SurveyEngine.setEmbeddedData(embeddedDataFieldname, text);*/
});
Both times, it tells me "null is not an object"
Am I missing something here?