How can I auto code a single/multi question from the response selected in previous question? | XM Community
Skip to main content
How can I auto code a single/multi question from the response selected in previous question? For example, out of 5 options in a multi question only 1 of them is selected at question Q1. I have to autocode this code in question Q2 which is also a multi question and skipped from been asked to the respondent. What is the best approach to implement it?
@Sumeshsdn I am not sure what you mean when you say autocode. But it sounds like you are interested in either the carry forward option or piping options available through Qualtrics. Since I don't completely understand what you mean by autocode, I can't give complete advice on which to use, but their help pages are linked for you to check out.
Don't skip the 2nd question. Carry forward the selected choices in the 1st question to the 2nd question, and add JS to the 2nd question to count the number of choices. If there is one choice, select it and either click the next button (if it is the only question the page) or hide it (if there are other questions on the page).
> @TomG said:

> Don't skip the 2nd question. Carry forward the selected choices in the 1st question to the 2nd question, and add JS to the 2nd question to count the number of choices. If there is one choice, select it and either click the next button (if it is the only question the page) or hide it (if there are other questions on the page).



Hi @TomG, thanks for your suggestion. I think that would help :-)

I would also like to know it there is any other way we can write scripts for custom programming other than Javascript? I am a newbie with Javascript so unsure of how I can select choices with it.
> @Sumeshsdn said:

> I would also like to know it there is any other way we can write scripts for custom programming other than Javascript? I am a newbie with Javascript so unsure of how I can select choices with it.

No, JavaScript is the only way to accomplish the task. Use the Qualtrics Question API to select choices. For example, to select the choice with choiceId 1 in a Multiple Choice question you would use:

```

this.setChoiceValue(1, true);

```
> @TomG said:

> > @Sumeshsdn said:

> > I would also like to know it there is any other way we can write scripts for custom programming other than Javascript? I am a newbie with Javascript so unsure of how I can select choices with it.

> No, JavaScript is the only way to accomplish the task. Use the Qualtrics Question API to select choices. For example, to select the choice with choiceId 1 in a Multiple Choice question you would use:

> ```

> this.setChoiceValue(1, true);

> ```

>

>



@TomG Thanks for the valuable information. I have worked in ConfirmIT before and in it the survey level scripting could be done using JScript. I was hoping for something similar in Qualtrics. Nevermind, an opportunity for me to work on my Javascript skills :-)

Thanks for your help!
@TomG, I tried using the below code but it doesn't seem to work. There are 2 multi question Q32 and Q36. When only 1 choice is selected at Q32 I am trying to code that option in Q36 and submit the page such that Q36 is shown to the respondent. The pipe text "${q://QIDQ32/SelectedChoicesCount}" is not working. It doesn't seem to return anything in alert function too. Let me know if you have any suggestions.



Qualtrics.SurveyEngine.addOnload(function()

{



var val1 = "${q://Q32/SelectedChoicesRecode}";

var val2= "${q://QIDQ32/SelectedChoicesCount}";



if(val2==1)

{



this.setChoiceValue(val1, true);

("#NextButton").submit();



}



});
@Sumeshsdn,



You have number of errors, including your pipes. However, you don't need to pipe anything. Use this script.
@TomG, Alright, so have checked the number of choices that are getting displayed using the getChoiceDisplayed() function and if only 1 choice is shown then it is auto-coded and the page is submitted. This is great! Thanks for your amazing assistance.

Leave a Reply