Have an idea?

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

SSI script error

I have the below SSI script to compute BMI score on the hidden variable. Can any one tell me what is the mistake here?

<input name="BMI" id="BMI" type="open" value="[% (WEIGHT/(HEIGHT*HEIGHT))* 703 %]">
asked Jul 6, 2012 by anonymous

2 Answers

0 votes
I would have done something like this ...

<input name="BMI_CODE" type="hidden" value="
Begin Unverified Perl

 my $BMI_code=0;
 return $BMI_code;
End Unverified

Pop this into a free format hidden question named BMI_CODE. Be sure the WEIGHT and HEIGHT variables have been answered and place this hidden question on a page where the base agrees with WEIGHT and HEIGHT bases. No good putting it on a page that is skipped.
answered Jul 6, 2012 by Paul Moon Platinum (101,255 points)
Hi Paul,

I tried your code. It is not working

Here is how I programmed questions in the survey.

1. Free format question capturing Feet and Inches for HEIGHT
2. Free format quesiton capturing WEIGHT in pounds
<page break>
3. having hidden variable to compute HEIGHT from feet and Inches
<input name="BMI1_HEIGHT" id="BMI1_HEIGHT" type="open" value="[% (D24_A*12)+D24_B %]">

<page break>
4. having hidden variable to calculate BMI
<input name="BMI2_BMI" id="BMI2_BMI" type="open" value="[%
 Begin Unverified Perl
 my $BMI2_BMI=0;
 return $BMI2_BMI;
 End Unverified

Intially I was able to calculate using the below code and later it didn't work.
<input name="BMI2_BMI" id="BMI2_BMI" type="open" value="[% (D25_A/(BMI1_HEIGHT*BMI1_HEIGHT))*703 %]">
I just tested my code and it worked nicely.

I had 2 numeric questions, one to capture weight and one to capture height.

I had a select question on the next page with the free format hidden question on the same page.

Be sure to take case sensitivity into account as this is critical to Perl. All your variables and functions need to respect this rule.

I also noticed you had "type=open". I used "type=hidden".

Use [%Value(BMI_CODE)%] on another page to test if it works okay.

You can also convert your height all in the same hidden variable.

Let me know how you go.

I can send you my Sawtooth test file if you like.
0 votes
Your variable type is set to open, which might be the cause of the problem if it's not being saved.

If you wanted to double check things, in this case I would break the two things you are doing into separate steps.  To test the script, take the math portion inside SSI Script tags and toss it into the header of the following page and make sure that part of it is working.  To test the HTML, make it a normal variable where you saving a hard-coded value and make sure it gets saved to the respondent data record.  If both parts work independently, they should work together.
answered Jul 6, 2012 by Brian McEwan Platinum Sawtooth Software, Inc. (56,775 points)
Thanks Brian! It works now!