Have an idea?

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

Javascript Verification

Hi,
 
I’m trying to create some custom javascript verification for a question with a specify box (numeric) and a don’t know option. The list people select from is built from a previous question so it also needs to confirm that the answer option has been pulled through.
 
I have set this up and it works fine when only verification for 1 row of the question is turned on i.e:
 
if(SSI_GetValue("shp8b_r5_c1") >= 1 && SSI_GetValue("shp8b_r5_c2") == 1)
{strErrorMessage="Please enter a value OR select 'Don't Know' for each of the drinks shown";}
if(SSI_GetValue("shp8b_r5_c1") == "" && SSI_GetValue("shp8b_r5_c2") == 0 && [%shp8_r5%] >=1)
{strErrorMessage="Please enter a value OR select 'Don't Know' for each of the drinks shown";}
 
However when I try and run it for rows 1,2,3,4,5,6&7 together it does not work. (the same code as above but for _r1, _r2 etc.
 
I’m not sure what I’m doing wrong as the script works just not when the whole thing is run.
 
Would be great if someone could tell me what I’m doing wrong!!
 
Cheers
James
asked Apr 7, 2017 by James

1 Answer

0 votes
A few potential concerns:

1. Does shp8 also use a constructed list?  If so, [% shp8_rX %] may return blank if X isn't in the constructed list.  Then your code ends up with this invalid script: "... && >= 1."  This little workaround will give you zero when the Sawtooth Script wants to return a blank string:

Number('[% shp8_rX %]')


2. When an item doesn't appear in the constructed list, SSI_GetValue may just always return a zero for it.  If this is a problem, you can use our Sawtooth Script function ListValuesArray to know which rows actually need to be verified in the custom JavaScript verification.

3. If I recall correctly, SSI_GetValue never returns a blank string for numeric fields; it returns zero instead.  To determine if a numeric field is blank, you can use jQuery instead:

$('#shp8b_rX_c1').val() === ''


Hopefully this is helpful for you.  I can be of assistance if you need anything else.
answered Apr 7, 2017 by Zachary Platinum Sawtooth Software, Inc. (69,875 points)
That's awesome thanks. Yes shp8 was a built list as well so using number (' ') did the trick. The first column of the question is an open numeric box and "" does work for this (and has worked for me with this in the past).

Thanks again
...