I have the following code for copying selected multiple choice text to an embedded data field "choice1":
`Qualtrics.SurveyEngine.addOnload(function()
{
var currentQuestionID = this.getQuestionInfo().QuestionID
console.log("Current Question ID is: " + currentQuestionID)
var resultEmbeddedName = "result_" + currentQuestionID.substring(3) //e.g. result_6
$('NextButton').onclick = function (event) {
var questionObject = Qualtrics.SurveyEngine.getInstance(currentQuestionID)
var currentResponse = questionObject.getSelectedChoices()[0] //in case more than one is selected, it will only work here to take one!
var theQuestionInfo=questionObject.getQuestionInfo()
var choicesObject=theQuestionInfo.Choices
var thisChoiceObject=choicesObject[currentResponse]
var currentChoiceText=thisChoiceObject.Text
console.log("Number of the current choice is " + currentResponse)
console.log("Text of the current choice is " + currentChoiceText)
Qualtrics.SurveyEngine.setEmbeddedData('choice1', currentChoiceText)
Qualtrics.SurveyEngine.navClick(event, 'NextButton')
}
});`
Basically, this code works once, on the first question displayed, but then when I try to copy future responses to fields "choice2", "choice3" etc. it stops working. Does anybody know why this could would only work once in a survey?
Thank you!
Josh
Best answer by TomG
View original