Have an idea?

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

Grid with rules for column total

I have a grid question with 7 rows of locations, each with a select Yes or No from radio button (2 columns).

Question direction is Rows. Each of the 7 rows is required to respond (Yes or No)

I want to ensure that at least one row has Yes selected. Is there any way I can do this and include an error message like: "You must respond YES to at least one location".

I have a feeling there is probably a very simple solution that I am not seeing (in my defense it is late Friday afternoon my time).
asked Feb 17, 2017 by Christine Hanley (370 points)

1 Answer

+1 vote
 
Best answer
Pop the JavaScript below into your grid question. I have assumed it is Q1.

Click on the Advanced button and  select the Custom JavaScript Verification tab.
var yescount = 0;

for (var r = 1; r <= 7; r++)
 {
  if (SSI_GetValue('Q1_r' + r) == 1)
    {
     yescount = yescount + 1;
    }
  }

if (yescount == 0)
 {
  strErrorMessage = 'You must select YES at least once';
 }
answered Feb 17, 2017 by Paul Moon Platinum (76,675 points)
selected Feb 18, 2017 by Christine Hanley
Thanks Paul. Sadly this didn't work. Likely my fault - I think I've gone beyond making any sense even to myself.

 "Yes" is column 1, "No" is column 2.  I need them to Select Yes at least once (so able to select No a maximum of 6 times). I don't know if that helps! Sorry for the bother. Won't be offended if you give up on me!
This should work in v8 and v9.

I tested this in v9.2.0 and it worked a treat.

What is your question number? You need to change the following line to your respective question number ...

Change "Q1_r" to "?_r" where "?" is your question number.

if (SSI_GetValue('Q1_r' + r) == 1)

Does that help?
I'm using V8.4.8 so that shouldn't be a problem. I did change the question number as you describe (mine is Q10). Just triple checked all again. I cannot figure out why it's not working. Thanks for your help anyway.
I have it working where at least one YES must be mentioned, otherwise the error will be displayed.

Just tested it in v8.4.8 also and it works beautifully.

Send me your ssi file with Q10 only and I will check out what is causing you grief.

Email: paulmoon@aapt.net.au
Thanks so much Paul. I've thrown in the towel today, and will try again tomorrow. Hopefully I won't need to bother you with it again.
Hi Paul. Have sent you an email. Thanks in advance for any help or advice you might have.
Thanks Christine for sending the ssi file to me. You copied the "[code]" tags from the forum into the JavaScript. Simply remove them and your JavaScript will work as requested. I sent you my contact details if you get stuck. Regards.
Thank you Paul. Perhaps I should add the tag "duh" to this post! So sorry for my stupidity!
No worries. This is how you learn.
With Q10 I want to make Row 7 (other specify) forced response to the text box ONLY if they select YES. At the moment I have it set to required response but this triggers the “a response is required” message even if I tick no. Any ideas?
Start by disabling the built-in required response.  Then, after Paul's code, add this:

if (SSI_GetValue('Q10_r7') == 1 && !SSI_GetValue('Q10_r7_other')) {
    strErrorMessage = 'Other specify error';
}
Perfecto! Thanks Zachary!
Good one Zachary. Thanks for chipping in. Onya mate. Nice work as always.
...