Have an idea?

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

Custom JavaScript Verification NOT Working for Error Message

I have two grid questions (A3 and A4) where I want to validate that the responses in each row in question A4 is not greater than the same question in each row in question A3.

I have the following code snippet that is not working when I am comparing A4 > A3.  The code seems to work if I set the comparisons to fixed values.  For example, if I write (SSI_GetValue("A4_r1_c1") > 5 ) instead of (SSI_GetValue("A4_r1_c1") > SSI_GetValue("A3_r1_c1")).

Help?!!


if(
    (SSI_GetValue("A4_r1_c1") > SSI_GetValue("A3_r1_c1")) ||
    (SSI_GetValue("A4_r2_c1") > SSI_GetValue("A3_r2_c1")) || 
    (SSI_GetValue("A4_r3_c1") > SSI_GetValue("A3_r3_c1")) 
  )
    {
    strErrorMessage = "Error in A4.";
    } 

asked Mar 5 by anonymous

1 Answer

0 votes
 
Best answer
We cannot get the value of A3 question in A4 question using SSI_GetValue instead use perl function to retrieve the value of A3.

We can use SSI_GetValue function to retrieve the value of a variable which is present in page currently displayed. For getting the value of already answered question, we need to use perl.

I have edited your piece of code and placed below,

if(
    (SSI_GetValue("A4_r1_c1") > [% A3_r1_c1 %] ) ||
    (SSI_GetValue("A4_r2_c1") > [% A3_r2_c1 %] ) || 
    (SSI_GetValue("A4_r3_c1") > [% A3_r3_c1 %] ) 
  )
    {
    strErrorMessage = "Error in A4.";
    } 
answered Mar 5 by KarthikMahankali Bronze (2,505 points)
Thank you! Lesson learned for today.  :-)
...