Have an idea?

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

Grid question - javascript verification

Dear All,

Maybe someone here would be able to help ?
I got a grid question with 12 purchase criteria (in rows) and 3 columns (Low importance = 1 ,mid importance = 2  and high importance = 3). We want respondents to select max. 4 criteria
with high importance and at least 4 with low importance.  Im a bit critic to this approach but this is client wish and need to program it.

The issue Im struggling with is checking how many criteria were selected and then implementing an error message. Im trying to use JavaScript verification tab with the below
code but Im not very familiar with this language. For the beggining got below code :

if (Q2_r1==3) var  int_r1;
if (Q2_r2==3) var  int_r2;
if (Q2_r3==3) var  int_r3;
if (Q2_r4==3) var  int_r4;
if (Q2_r5==3) var  int_r5;
if (Q2_r6==3) var  int_r6;
if (Q2_r7==3) var  int_r7;
if (Q2_r8==3) var  int_r8;
etc.
if (Q2_r12==3) var  int_r12;
{

if((int_r1+int_r2+int_r3+int_r4+int_r5+ ... int_r12)>12)
{
strErrorMessage = "You cannot select more than 4 times "high importance";
}
}

but it doesn't work. Can someone help ?
12 is because 4x high importance (= 4*3 )

All the best,
robson
asked Dec 3, 2013 by robson Bronze (700 points)

1 Answer

+1 vote
 
Best answer
Please review below code. You need to use SSI_GetValue function to get value for variable.

var int_r1=0;
var int_r2=0;
var int_r3=0;
var int_r4=0;
var int_r5=0;
var int_r5=0;
var int_r6=0;
var int_r7=0;
var int_r8=0;
var int_r9=0;
var int_r10=0;
var int_r11=0;
var int_r12=0;

if(SSI_GetValue('Q2_r1')==3)
{
    int_r1=3;
}
if(SSI_GetValue('Q2_r2')==3)
{
    int_r2=3;
}
if(SSI_GetValue('Q2_r3')==3)
{
    int_r3=3;
}
if(SSI_GetValue('Q2_r4')==3)
{
    int_r4=3;
}
if(SSI_GetValue('Q2_r5')==3)
{
    int_r5=3;
}
if(SSI_GetValue('Q2_r6')==3)
{
    int_r6=3;
}
if(SSI_GetValue('Q2_r7')==3)
{
    int_r7=3;
}
if(SSI_GetValue('Q2_r8')==3)
{
    int_r8=3;
}
if(SSI_GetValue('Q2_r9')==3)
{
    int_r9=3;
}
if(SSI_GetValue('Q2_r10')==3)
{
    int_r10=3;
}
if(SSI_GetValue('Q2_r11')==3)
{
    int_r11=3;
}
if(SSI_GetValue('Q2_r12')==3)
{
    int_r12=3;
}

var sum=int_r1+int_r2+int_r3+int_r4+int_r5+int_r6+int_r7+int_r8+int_r9+int_r10+int_r11+int_r12;
if(sum>12)
{
    strErrorMessage = "You cannot select more than 4 times 'high importance'";
}


Let me know for more help.
answered Dec 3, 2013 by Rajesh Rana Gold (23,660 points)
selected Dec 4, 2013 by robson
Thank you Ranarajesh85 but unfortunatelly it doesn't work.  The soft enables to go further and doesn't generate any error message to stop me if selected are more than 4x high importance....
OK sorry, I missed to initialize int_r10. Can you copy this code now and check.
Ranajesh you are great! Now it works perfect  ! Thank you very much ! This forum is probably the best professional forum I know. Thank you once again.
...