Have an idea?

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

cross-checks

I have a few cross-checks that I want to add.  Given the above, I tried to structure something but I do not know javascript. If I want to make sure the response in the current question (D52) is the same as the # of HHmembers that responded "2" in A4b1 (asked per respondent) + the number in A15  +the HHhead (1), how would I write this?
var members = 'HHmembers'&& [% A4b1%]==2
if((SSI_GetValue('members')+ 1+ ('A15') !=('D52')
{
    strErrorMessage = 'Please verify # of people in home.';
}
asked Feb 3, 2021 by sallen Bronze (2,315 points)
edited Feb 3, 2021 by sallen

1 Answer

+1 vote
I'm no javascript expert, but a couple of things to keep in mind.  SSI_GetValue should be used for any question on the current page.  If the question is on a previous page you need to use Sawtooth Script [% %] to call that question's response.  Given that, I have assumed that all questions are on previous pages except for D52.  In the following script I first set a variable that adds the question HHmembers, the value of 1 and A15 together.  Then the if statement is looking to execute if A4b1 is a 2 and the variable totmembers does not equal the response to D52.  If those assumptions are correct, I believe I have the below javascript correct.


var totmembers = [% HHmembers %] + 1 + [% A15 %]
if([% A4b1 %]==2 && (totmembers != SSI_GetValue('D52'))
{
    strErrorMessage = 'Please verify # of people in home.';
}
answered Feb 3, 2021 by Jay Rutherford Platinum (50,145 points)
My unverified Perl should do that.  Have you tried it?
I was not sure how to combine the steps above in a way that captures the constraint on A4b1.  I think a note in the footer would work better rather than a cross check in this case however.
My unverified Perl already has a conditional that checks A4b1.  What behavior do you need that differs from that?
Ok.  I didn't realize I can also just use that in the footer as a note rather than a check.  I will try that.
That works great. Thanks!
...