# Trying to assign values to a grid based on lowest value assigned

Here is my issue.  I have a grid type question and the headings are
1. 0%-(do not do this)
2. (1% to 19%)
3. (20% to 39%)
4. (40% to 59%)
5. (60% to 79%)
6. (80% or more)

There are 7 items in the rows...

This is a select type grid.  The respondent is to check each row with one of the above percents - however - they cannot go over 100%... I need to count each response with the lowest value - so for instance if someone selects the 20%-39% choice, that would be counted as a 20%, a 1%-19% would be 1%, and so on.  Then when they are done, I need to sum all responses up and make sure their total does not equal 100% or more...

I know that it can be done in a constant sum, but I need to figure it this way.  This is my logic so far, but it's not working... I hope this isn't too confusing. Thanks.

var counter = 0;

if (SSI_GetValue("S1_r1") = 1){counter = counter + 0;}
if (SSI_GetValue("S1_r2") = 1){counter = counter + 0;}
if (SSI_GetValue("S1_r3") = 1){counter = counter + 0;}
if (SSI_GetValue("S1_r4") = 1){counter = counter + 0;}
if (SSI_GetValue("S1_r5") = 1){counter = counter + 0;}
if (SSI_GetValue("S1_r6") = 1){counter = counter + 0;}
if (SSI_GetValue("S1_r7") = 1){counter = counter + 0;}

if (SSI_GetValue("S1_r1") = 2){counter = counter + 1;}
if (SSI_GetValue("S1_r2") = 2){counter = counter + 1;}
if (SSI_GetValue("S1_r3") = 2){counter = counter + 1;}
if (SSI_GetValue("S1_r4") = 2){counter = counter + 1;}
if (SSI_GetValue("S1_r5") = 2){counter = counter + 1;}
if (SSI_GetValue("S1_r6") = 2){counter = counter + 1;}
if (SSI_GetValue("S1_r7") = 2){counter = counter + 1;}

if (SSI_GetValue("S1_r1") = 3){counter = counter + 20;}
if (SSI_GetValue("S1_r2") = 3){counter = counter + 20;}
if (SSI_GetValue("S1_r3") = 3){counter = counter + 20;}
if (SSI_GetValue("S1_r4") = 3){counter = counter + 20;}
if (SSI_GetValue("S1_r5") = 3){counter = counter + 20;}
if (SSI_GetValue("S1_r6") = 3){counter = counter + 20;}
if (SSI_GetValue("S1_r7") = 3){counter = counter + 20;}

if (SSI_GetValue("S1_r1") = 4){counter = counter + 40;}
if (SSI_GetValue("S1_r2") = 4){counter = counter + 40;}
if (SSI_GetValue("S1_r3") = 4){counter = counter + 40;}
if (SSI_GetValue("S1_r4") = 4){counter = counter + 40;}
if (SSI_GetValue("S1_r5") = 4){counter = counter + 40;}
if (SSI_GetValue("S1_r6") = 4){counter = counter + 40;}
if (SSI_GetValue("S1_r7") = 4){counter = counter + 40;}

if (SSI_GetValue("S1_r1") = 5){counter = counter + 60;}
if (SSI_GetValue("S1_r2") = 5){counter = counter + 60;}
if (SSI_GetValue("S1_r3") = 5){counter = counter + 60;}
if (SSI_GetValue("S1_r4") = 5){counter = counter + 60;}
if (SSI_GetValue("S1_r5") = 5){counter = counter + 60;}
if (SSI_GetValue("S1_r6") = 5){counter = counter + 60;}
if (SSI_GetValue("S1_r7") = 5){counter = counter + 60;}

if (SSI_GetValue("S1_r1") = 6){counter = counter + 80;}
if (SSI_GetValue("S1_r2") = 6){counter = counter + 80;}
if (SSI_GetValue("S1_r3") = 6){counter = counter + 80;}
if (SSI_GetValue("S1_r4") = 6){counter = counter + 80;}
if (SSI_GetValue("S1_r5") = 6){counter = counter + 80;}
if (SSI_GetValue("S1_r6") = 6){counter = counter + 80;}
if (SSI_GetValue("S1_r7") = 6){counter = counter + 80;}

if (counter > 100) {strErrorMessage = "Your percentage used is more than 100%, please review your answers.";}

We are using 7.0.30
asked Jun 27, 2017
Brian has it exactly right.  As an optional change, you can shorten up some of this code using looping.  Here is the last block of your code in a for loop:

```for (var r = 1; r <= 7; r++) {
if (SSI_GetValue('S1_r' + r) == 6) {
counter += 80;
}
}
```

If you really want to cut it down, you can create what is known as a dictionary to convert SSI_GetValue's output into how much the counter needs to be incremented.  Here's all six of your blocks done with a dictionary and a loop:

```var increments = {
1: 0,
2: 1,
3: 20,
4: 40,
5: 60,
6: 80
};
for (var r = 1; r <= 7; r++) {
counter += increments[SSI_GetValue('S1_r' + r)];
}
```

## 1 Answer

0 votes
You need double equal signs for comparisons, i.e. if(SSI_GetValue("Sq_r1")==0)
answered Jun 27, 2017 by Gold (38,315 points)
Was SSI_GetValue in v7? Testing my memory here?
I wasn't sure, I had to go back and check our release notes :)
I suspect v8 was when it was introduced so v7 won't like it?
No it's in version 7, I found a bug release note about a fix to SSI_GetValue() which was introduced in 8.0, meaning the function existed in 7 (not sure if it was a 7.0 feature though).
Thanks Brian. Then v7 is safe to use the function. Just straighten up the Perl scripting and all is well.