Have an idea?

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

Javascript SSI_SetSelect

Hi all,

Got one hell of a problem here that I've been trying to throw whatever I can at but to no avail...

The top half of my JS is absolutely fine. What I need to do is push the contents of the vars adults, seniors, YA2224, YA1821, juniors & kids into another question... reason being is that the question is not mandatory, but I have to calculate based off the back of the responses (0 is code 1 so I need to minus 1 from each response, blank = 0 so -1 once I subtract)

I'm stuck with SetSelect

So basically, what I want to do is

STPI2RECALC_r1_c1 = STPI2_r1_c1
EXCEPT where STPI2_r1_c1 is blank, then recode STPI2RECALC_r1_c1 = 1

Any idea what I need to do with the bottom part of my code?

It has to run on the JS verification part, the next question uses these calcs with a skip logic. After clicking next.

Appreciate any tips!

var strErrorMessage = "";
var adults = SSI_GetValue("STPI2_r1_c1");
var seniors = SSI_GetValue("STPI2_r2_c1");
var YA2224 = SSI_GetValue("STPI2_r3_c1");
var YA1821 = SSI_GetValue("STPI2_r4_c1");
var juniors = SSI_GetValue("STPI2_r5_c1");
var kids = SSI_GetValue("STPI2_r6_c1");

if (adults < 2 && seniors <2 && YA2224 <2 && YA1821 <2) 
    strErrorMessage = 'Please select at least one ticket aged 18+';

if(adults < 2)

asked Apr 20 by crawliano (380 points)
So STPI2RECALC is on the page after STPI2, correct?
Correct and I'd like to populate that with the answers before the skip logic kicks into life. STPI2RECALC is between STPI2 and STPI3
Are these pre-skips, then?  Are respondents meant to not actually see STPI2RECALC?
Not really

What I want to do is run the JS to populate STPI2RECALC and then run the skip logic from what I've calculated to determine whether STPI3 is shown or STPI4

Just thinking out loud here...  Couldn't I prefill the answers for the question and do this that way? So actually set the response in the raw data and if the respondent changes the dropdown only then the held data would change, so default all answers to 1 (as in the response for 0) and then on change, this would then update the way I want and negate the need for all of this?

Might be trying to crack a walnut with a sledgehammer here...
I think the core of the problem we're having is that you cannot use JavaScript to set a value not on the current page.  So we need to find another way to approach this.

If respondents are meant to see STPI2RECALC, then I would rework part of the code from STPI2's custom JavaScript verification to STPI2RECALC's footer.  So you would use Sawtooth Script to get the STPI2 responses, then use JavaScript / SSI_SetSelect to pre-select the values we want.

If respondents aren't meant to see STPI2RECALC, then I'm not sure we need STPI2RECALC to exist at all.  If it's just a middleground for some skips, then we can rework the skip logic to perform whatever calculations that we would have done with STPI2RECALC.

Your solution to the original question

Please only use this to answer the original question. Otherwise please use comments.
Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:

To avoid this verification in future, please log in or register.