I feel as though I have been able to do this in the past, but doesn't appear to be working now. Was hoping somebody could troubleshoot with a solution.
We often ask multiple choice questions that then drill down into further questions that have carried forward choices from that initial question. For instance, Q1 would ask to select all product users in the home and then Q2 would ask who is the primary product user in the home (carrying forward only selected choices from Q1).
In the case where only 1 choice is made at Q1, I would like to automatically select that response at Q2 and hide it so the respondent doesn't see it.
Here is a snippit of the Javascript I am using to try to accomplish this that isn't working. Essentially saying that if only one choice was selected at the previous question (QID27 in this case) and that choice was X, then select X at this question and skip.
Any thoughts would be appreciated!
Qualtrics.SurveyEngine.addOnload(function()
{
if ("${q://QID27/SelectedChoicesCount}" == 1 && "${q://QID27/SelectedChoicesRecode}" == 1 ) {
this.setChoiceValueByRecodeValue(1, true);
this.getQuestionContainer().hide();
this.clickNextButton();
}
else if ("${q://QID27/SelectedChoicesCount}" == 1 && "${q://QID27/SelectedChoicesRecode}" == 2 ) {
this.setChoiceValueByRecodeValue(2, true);
this.getQuestionContainer().hide();
this.clickNextButton();
}
else if ("${q://QID27/SelectedChoicesCount}" == 1 && "${q://QID27/SelectedChoicesRecode}" == 3 ) {
this.setChoiceValueByRecodeValue(3, true);
this.getQuestionContainer().hide();
this.clickNextButton();
});
Solved
JavaScript to Autopopulate a response issues
Best answer by TomG
> @GeoffK said:
> Tom, thanks once again! You are amazing. This is a much more simple solution, and more foolproof.
>
> One more question on your 2nd comment. I do see that hiding doesn't do any good because it still flashes. Not being fluent in coding, do you have an example of adding the empty div and what that would look like + where exactly to input it?
HTML:
```
<div id="padTop" style="padding-top:2000px"></div>
Your question text
```
JS (if JS doesn't click next):
```
jQuery("#padTop").hide();
```
View original> Tom, thanks once again! You are amazing. This is a much more simple solution, and more foolproof.
>
> One more question on your 2nd comment. I do see that hiding doesn't do any good because it still flashes. Not being fluent in coding, do you have an example of adding the empty div and what that would look like + where exactly to input it?
HTML:
```
<div id="padTop" style="padding-top:2000px"></div>
Your question text
```
JS (if JS doesn't click next):
```
jQuery("#padTop").hide();
```
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.