Have an idea?

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

Display previous question answer in question text

I'd like to insert the answer given prior question (radio button select) into the text of a future question. For example - in Q3 the respondent picks their favourite cake, in Q7 we say "What do you like about XX cake?"

I'm sure it's very easy, but I am not embarrassed to admit I've failed ask for help!

Thanks in advance for any advice!
asked Nov 26, 2014 by Christine Hanley (370 points)
edited Nov 26, 2014 by Walter Williams

1 Answer

0 votes
You can use [%Label(Q3)%] as piping the cake through to Q7. I'm assuming Q3 is a single response select question.

Be careful of the question name you are referring to as different questions have different naming - e.g. grid questions differ from select questions.

You can check the naming convention of any question through the admin module for example when checking a survey's data.
answered Nov 26, 2014 by Paul Moon Platinum (74,205 points)
Apologies, I changed "Value" to "Label".
Thanks Paul. Sorry to be a bother... How should the preceding java text/instruction be formatted?  I'm using the below script and recieving an error.

<script type="text/javascript">


All you need to do is pop [%Label(Q3)%] into the Header 1 / Header 2 / Question / Footer windows within Q7. Not sure where you are trying to place it but any of those windows will work.

This is not JavaScript. It is SSI Script which is very powerful in Sawtooth. Lots of neat functions included in the Sawtooth library. Look up SSI Script in the Sawtooth help.

Tip - hit F1 in any window in Sawtooth and the help will appear.
Thanks Paul! It was working all along and I was just over-complicating things! And it's not even Friday yet...
Good news. Only use SSI Script in piping situations like this. JavaScript is very handy but not required here.
Hi.. Is there any other way other than using this [%%] in javascript to get values from previous page..?
need this to take it in a loop as [% %] is not taking in for loop value..
The value for your loop variable can be displayed by using something like this rather than JavaScript...

[%Q1.1%] or [%Q1.2%]

I'm not sure if you are trying to display the loop or step-through controller variable or a variable within the loop?

You need the correct name of your loop if it is not the step-through variable and if you are unsure, do a test survey and look at the data via the admin module by selecting the view option. This will display all variable names within your survey.

Also, you have a host of SSI Script loop functions like LOOPLABEL(), LOOPVALUE(), LOOPITERATION() to name a few.

LOOPLABEL() is probably the function you are looking for as a guess in this situation as it will display the step-through variable at each question.

Q1. How old is [%LOOPLABEL()%] ?

will display 1st time through the loop - Q1. How old is Person 1?
will display 2nd time through the loop - Q1. How old is Person 2?
will display 3rd time through the loop - Q1. How old is Person 3?