Have an idea?

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

How can I create a hidden variable?

I have the following hidden variable:

Hidden_Edu [S]
1. Small
2. Medium
3. Large

And I want to assign it to categories based on Q1
1. Small: Q1=1-4
2. Medium: Q1=5-7
3. Large: Q1=8-9

I tried to write the following, but unfortunately wasn't working:

<input name="HIDEDU_SMALL" id="HIDEDU_SMALL" type="hidden" value = "Q1_1 Q1_2 Q1_3 Q1_4">
<input name="HIDEDU_MEDIUM" id="HIDEDU_MEDIUM" type="hidden" value = "Q1_5 Q1_6 Q1_7">
<input name="HIDEDU_LARGE" id="HIDEDU_LARGE" type="hidden" value = "Q1_8 Q1_9">

Can you help me please?
asked Jul 28 by anonymous

2 Answers

0 votes
You can define Pass-In fields and set their data type as a whole number.

Call them Q1Small / Q1Medium / Q1Large.

Insert this Perl Script in any question footer after Q1 has been answered and ensure that particular question is not skipped.
[%Begin Unverified Perl 

 SETVALUE("Q1Small",0);  
 SETVALUE("Q1Medium",0);
 SETVALUE("Q1Large",0);  

 if (VALUE("Q1_1")==1 || VALUE("Q1_2")==1 || VALUE("Q1_3")==1 || VALUE("Q1_4")==1)
  {
   SETVALUE("Q1Small",1);  
  }

 if (VALUE("Q1_5")==1 || VALUE("Q1_6")==1 || VALUE("Q1_7")==1)
  {
   SETVALUE("Q1Medium",1);  
  }

 if (VALUE("Q1_8")==1 || VALUE("Q1_9")==1)
  {
   SETVALUE("Q1Large",1);  
  }

End Unverified%]

This will set Q1Small / Q1Medium / Q1Large all to "0". If any of the respective conditions are true, they will be set to "1".

These 3 variables are available to export as you would any other variable. You can also use them in skip logic, list building, etc.
answered Jul 28 by Paul Moon Platinum (82,475 points)
0 votes
You can simply do this using constructed list:

Below is the code if you are using the free-format variables, considering Q1 to be a single select question and freeformat variable is made after Q1 on a separate page:

<input name="HIDEDU_SMALL" id="HIDEDU_SMALL" type="hidden" value = "
[% Begin Unverified Perl
my $ab=VALUE('Q1');
if($ab ge 1 && $ab le 4){return 1;}
End Unverified %]
">


Similarly change for other variables.

Regards,
Rahul Mittal
answered Jul 28 by Rahul Mittal Bronze (4,980 points)
Do you know how can I make this on the same page?
I mean..I don't want to have a separate page with the hidden variable..
I tried to delete the page break between the question Q1 and the hidden variable, but unfortunately I got an error :(
Any specific reason of doing on same page. I think you are creating on a fully separate and you dont want to click next button.

You can keep it on next page along with other question so that free-format variable is not visible and data is stored at the backend.

Hope this helps.
Yes, it worked now. Thank you very much!
Here is the code to do it on same page:

Copy it in HTML area of FF question-
<input name="HIDEDU_SMALL" id="HIDEDU_SMALL" type="hidden" value = "">

Copy it in Footer of the free-format question -
<script>
setInterval(function(){
    if(SSI_GetValue("Q1")>=1 && SSI_GetValue("Q1")<=4){$("#HIDEDU_SMALL").val(1);}else{$("#HIDEDU_SMALL").val('');}
},100);
</script>
Wonderful! Thank you very much!
...