Have an idea?

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

Javascript Validation of numeric value based on previous answer

I have 2 questions in two separate pages:

S1 is a radio question with values from 1 to 6.
S2  is a grid question with numeric open text boxes.

I want to validate the values in S2 based on answers in S1.

I put the code below in the Advanced Settings Custom Java Verification area for S2 but it doesn't show the error and doesn't let me move forward.

If I put it in the footer for S2, nothing happens either. I can move to the next question with no error message.

if (
(SSI_GetValue("S2_r1_c1")<=10  && "[% S1 %]"==2) || (SSI_GetValue("S2_r1_c1")>=24 && "[% S1 %]"==2))
    strErrorMessage = 'Please enter a correct value between 10 and 24.';
}
if (
(SSI_GetValue("S2_r2_c1")<=10  && "[% S1 %]"==3) || (SSI_GetValue("S2_r2_c1")>=24 && "[% S1 %]"==3))
    strErrorMessage = 'Please enter a correct value between 25 and 49.';
}


What is wrong with this code? Thanks!
asked Sep 6 by rinsights Bronze (740 points)

1 Answer

0 votes
 
Best answer
Dear user,

Please insert a "{" before strErrorMessage in the Advanced Settings Custom Java Verification area. So, your error message will look like below:

if((SSI_GetValue("S2_r1_c1")<=10  && "[% S1 %]"==2) || (SSI_GetValue("S2_r1_c1")>=24 && "[% S1 %]"==2))
{
    strErrorMessage = 'Please enter a correct value between 10 and 24.';
}
if((SSI_GetValue("S2_r2_c1")<=25  && "[% S1 %]"==3) || (SSI_GetValue("S2_r2_c1")>=49 && "[% S1 %]"==3))
{
    strErrorMessage = 'Please enter a correct value between 25 and 49.';
}

Regards,
Rahul Mittal
answered Sep 7 by Rahul Mittal Gold (11,135 points)
edited Sep 7 by Rahul Mittal
Thank you! It works now.
...