Have an idea?

Visit Sawtooth Software Feedback to share your ideas on how we can improve our products.

Set response

Hello. I have two question.
Q1. (multiple answers)
Brand1
Brand2
Brand3
Brand4

....
Qn. (multiple answers)
Brand1
Brand2
Brand3
Brand4

I want to set response to Qn with the selected answer from Q1.(when the page is loading to see the answer from Q1 checked)
I am using 6.6.18.
Thank you! Hope you can help me!
asked Oct 21, 2013 by catalin22 (410 points)
retagged Oct 21, 2013 by Walter Williams
Here is a for loop that will work for your single response question.

<script type="text/javascript">

for (i = 1; i <= 28; i++) {
if ([%Q2%] == i)
 {
   document.getElementById("Qn_" + i).checked = true;  }
}

</script>

I'm having some trouble getting the same script for your multiple response question (Q1) to function in a loop.  I'll post something if I can get that to work unless one of our javascript experts on the forum can do it.

1 Answer

+2 votes
Here is an example of selecting Brand1 at Qn if it was selected at Q1

<script type="text/javascript">
if ([%Q1_1%] == 1)

{
  SSI_SetSelect("Qn_1", true);
}
</script>
answered Oct 21, 2013 by Jay Rutherford Gold (23,220 points)
I am using version 6.6.18. i don't think SSI_SetSelect is available.
Try this.

<script type="text/javascript">
if ([%Q1_1%] == 1)

{
  document.getElementById("Qn_1").checked = true;
}
</script>
I put this in footer? or in Custom Java Script Verification?
Thanks, it works!
Sorry I just saw this, so you figured out it goes in the footer.  

Glad I could be of help.
Hy. I try to implement the script.
I have multiple question Q1(multiple), Q2(single), Q3(multiple), Q4(simple). All that question use same parent list. I want to set response in Qn all answers from Q1, Q2, Q3,Q4.
I try to implemente the script but i think there is too many "if" because  the parent list have 28 choises, totaly 108 If statement. How can i reduce the If number? maybe on single choise question? Thank you!
For a singe response question you wouldn't use the underscore.  

So if Q1 is multiple you used this: if ([%Q1_1%] == 1) for the first response at Q1.  For the second response at Q1 you would use if ([%Q1_2%] == 1).

If Q2 is singe you would use this: if ([%Q2%] == 1) for the first response at Q2.  For the second response at Q2 you would use if ([%Q2%] == 2).  

With 28 choices you could simplify the script for each question using a for loop.  I have some things on my plate this morning but I will try to work it up for you in a little bit if nobody else does.
I know that for single choise i use ([%Q2%] == 1). The problem is there is too many if statestmen. I appreciate if you could help me with a for loop. Thanks a lot for your help.
I also try  switch function but does not work.
...