Have an idea?

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

How to assign specific value to each choice option?


I am composing a survey that evaluate accessories package. each accessory has different price, and these accessories are separated by different groups.

Now, I set each group as a single choice question or multiple choice question. What I want to do is to sum up the selected options for all groups. For example,

Group 1, (single choice question)
1. Item A (price: 500)
2. Item B (price: 200)
3. None (price: 0)

Group 2, (multiple choice question)
1. Item A (price: 300)
2. Item B (price: 100)
3. Item C (price: 150)

If I choose Item A from Group 1 and Item B and C from Group 2, then the total price should be 500 + 100 + 150 = 750.
The 750 is the exact value what I need to get.

When I compose questions by select question type, it could not set specfic value to each option. Hence, is there any possible way to specify values behind each item via SSIWeb? I am using SSIWeb version 8.

Thank you very much for your great support on my request.
asked Feb 28, 2017 by ericdee Bronze (1,800 points)
retagged Feb 28, 2017 by Walter Williams

1 Answer

0 votes
Best answer
You can calculate a score like this using JavaScript (if you need the score on the same page as the questions) or in Perl (if you need to score on a different page).  Here's the Perl I used to print out the score for your two questions:

[% Begin Unverified Perl
my $total = 0;

# Radio question
if (GETVALUE('RadioQ') == 1) {
    $total += 500;
elsif (GETVALUE('RadioQ') == 2) {
    $total += 200;
elsif (GETVALUE('RadioQ') == 3) {
    $total += 0;

# Check question
if (GETVALUE('CheckQ_1')) {
    $total += 300;
if (GETVALUE('CheckQ_2')) {
    $total += 100;
if (GETVALUE('CheckQ_3')) {
    $total += 150;

return $total;
End Unverified %]
answered Feb 28, 2017 by Zachary Platinum Sawtooth Software, Inc. (95,975 points)
selected Feb 28, 2017 by ericdee
Thanks very much Zachary. It does help a lot. Just double check, there is no SSIscript like [% Function()%] that I could embed into each question, I have to implement this by Perl (show sum score on a different page), is that right?
One option that you might like is to store the total score in a free format variable or a pass-in field.  You could replace line 26 of my code with something like this:

SETVALUE('PassInField1', $total);

After doing this, you could print the total anywhere in the survey with just one line of Sawtooth Script:

[% PassInField1 %]
Thank you so much, Zachary. I will try as per your feedback.