Have an idea?

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

Perl code problem in hidden variable

Can anyone help me in understand the problem in the below code?

I have a question for Age with dropdown box and followed by hidden variable that groups age category. This code is not working.

<input name="HS2_Age" type="open" value="[% begin unverified perl
if (S2>=2 && S2<=9)
{
  HS2_Age=1;
}
elsif (S2>=10 && S2<=13)
{
  HS2_Age=2;
}
else
{
  HS2_Age=99;
}
end unverified %]"
>
asked Jul 5, 2012 by anonymous
retagged Sep 13, 2012 by Walter Williams
You need to return the value of HS2_Age

your code should look like
<input name="HS2_Age" id="HS2_Age" type="open" value="
[% begin unverified perl
 if (VALUE("S2")>=2 && VALUE("S2")<=9)
 {
   HS2_Age=1;
 }
 elsif (VALUE("S2")>=10 && VALUE("S2")<=13)
 {
   HS2_Age=2;
 }
 else
 {
   HS2_Age=99;
 }
return HS2_Age;
 end unverified %]
 "
 >

1 Answer

0 votes
 
Best answer
Use VALUE("S2") rather than S2, its case sensitive by the wy
answered Jul 5, 2012 by Bahadir Ozkurt Gold (16,980 points)
Still the problem exist. Here is the code after the adding VALUE for the variable.

<input name="HS2_Age" id="HS2_Age" type="open" value="
[% begin unverified perl
 if (VALUE("S2")>=2 && VALUE("S2")<=9)
 {
   HS2_Age=1;
 }
 elsif (VALUE("S2")>=10 && VALUE("S2")<=13)
 {
   HS2_Age=2;
 }
 else
 {
   HS2_Age=99;
 }
 end unverified %]
 "
 >
I'm on blackbwery hars to see it all...
Instead of your hsage = type return
That would return the value into the value of the input
Great! It works! Thanks a lot!
Given Perl is case sensitive, shouldn't the Perl start and end script be ..

"Begin Unverified Perl" and "End Unverified"? You code is all in lower case.

That should fix it.
That part would not be fed to Perl, it is SSIScript, thus case insensitive.
Thanks Bahadir and Paul for your inputs. I am able to store values in the hidden variable.
...