Have an idea?

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

Help with JavaScript Validation

Created a question that has both a numeric and below it a check box,

the validation needs to ensure that either the checkbox or the numeric is always answered there are 3 columns with 2 rows, this is what i have so far

if(SSI_GetValue("Q42_r1_c1") != 1 && SSI_GetValue("Q42_r2_c1") == "")
{strErrorMessage="Please enter a value OR select 'Don't Know'";}
asked Oct 27, 2020 by Unwatnederaser31 (120 points)
It appears that you are checking whether or not their numeric response is 1 specifically, but I'm not sure if that is what you want.  You could continue using SSI_GetValue for this, but note that SSI_GetValue returns 0 when the field is empty, so it shouldn't be used if you need different behavior with a 0 response and an empty response.  If you just want to check the length of their response, you could use this:

$('#Q42_r1_c1').val().trim().length == 0

Alternatively, "Not Applicable: Per Variable" from the Community Question Library can do this for you.  It can be used to require that each column either be answered or that a checkbox be selected.  You can download it from here:

Hey Zachary,

Really appreciate the quick response,

I'm actually just looking for a JS validation which checks if
either the numeric or the check box is answered
one of them should be or an error is triggered.

For some reason the IF commands don't seem to be working.
SSI_GetValue("Q42_r1_c1") != 1

This part of your conditional isn't checking that the numeric isn't answered - it's checking that the numeric isn't answered with a response of 1.  Replacing that part of the conditional with my code snippet might be what you're after.

Your solution to the original question

Please only use this to answer the original question. Otherwise please use comments.
Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:

To avoid this verification in future, please log in or register.