Copying a multiple choice selected option text to embedded data for multiple different questions. | XM Community
Skip to main content
Solved

Copying a multiple choice selected option text to embedded data for multiple different questions.

  • February 16, 2019
  • 2 replies
  • 44 views

Forum|alt.badge.img+6
Hello! 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

I'm surprised it worked at all because of the click handler on the Next button. Use addOnPageSubmit instead. Then delete the navClick line at the end. There are several things you are doing the hard way. For example, at the start of your script you could do this: ``` var currentQuestionID = this.questionId; var questionObject = this; ```

2 replies

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • Answer
  • February 18, 2019
I'm surprised it worked at all because of the click handler on the Next button. Use addOnPageSubmit instead. Then delete the navClick line at the end. There are several things you are doing the hard way. For example, at the start of your script you could do this: ``` var currentQuestionID = this.questionId; var questionObject = this; ```

Forum|alt.badge.img+6
  • Author
  • Level 1 ●
  • February 20, 2019
Very appreciated Tom. This worked.