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 (56,965 points)
selected Feb 18, 2017 by Christine Hanley
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.