Have an idea?

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

How to make a grid qiestion which doesn't allow concurrent answers.

Hello,

I am trying to set up a grid question in Sawtooth, which will not only disallow unanswered questios (rows) but will also not allow users to select one and the same option at the same time.

I know that I can do that using a ramdm kind of question but I want to lay it out differently so grid will give me the visual style that I want in this case - it's just difficult to find an option which stops users select the same option at the same time.

Example:

............................... Question1 ... Question 2 ... Question 3 ... Question4 ...Question 5
Most important         "Tick Box"     "Tick Box"      "Tick Box"      "Tick Box"    "Tick Box"
Least important        "Tick Box"     "Tick Box"      "Tick Box"      "Tick Box"    "Tick Box"
asked Nov 16, 2011 by anonymous
what's your version?
Hi there,

It's Sawtooth 7.0.22.

Thanks,

Nadia

4 Answers

+3 votes
Try using javascript validation.

If the responses are all radio buttons, it would be:

if(SSI_GetValue("YourQuestion_r1") == SSI_GetValue("YourQuestion_r2"))
{
  strErrorMessage = "You can't choose the same thing in both rows.  Please review your answers and try again.";
}


In the case where you have a grid question with all multi response (ie tick boxes) and you want to restrict answers (say, brands going down, and attitude/use going across, with "This is my favourite" as one of the options, to be chosen for no more than one brand), you could also use javascript validation to prevent any more than one being chosen.  The following example presumes 10 brands:

var all = 0;

for(var b = 1; b <= 10; b++)
{
  if(SSI_GetValue("YourQuestion_r"+b) != null)
  {
    if(SSI_GetValue("YourQuestion_r"+b) == 1)
    {
      all = all + 1;
    }
  }
}

if(all > 1)
{
  strErrorMessage = "You can't choose more than ONE brand as your FAVOURITE one.";
}
answered Nov 16, 2011 by Marion Bronze (3,380 points)
edited Nov 16, 2011 by Marion
0 votes
Other way is just to block incorrect selection:
(for example for grid question test with 2 raws you can add the script into question footer)


<script type="text/javascript">  
 <!--
function SSI_CustomGraphicalRadiobox(GraphicalRadioboxObj, InputObj)   
{
var Raw1 = SSI_GetValue("test_r1");
var Raw2 = SSI_GetValue("test_r2");
if (Raw1 == Raw2) {
    InputObj.checked = false;
        //InputObj.value =0;
    GraphicalRadioboxObj.removeClass("radioboxselected");
    GraphicalRadioboxObj.addClass("radiobox");
}
}
 //-->

</script>
answered Nov 17, 2011 by anonymous
Please note that it is a decision for GRAPHICAL radio boxes in 7.0.26
0 votes
How's about if I put it in this way,

............................. Most important ... Least important
Question 1                "Tick Box"             "Tick Box"
Question 2                "Tick Box"             "Tick Box"
Question 3                "Tick Box"             "Tick Box"
Question 4                "Tick Box"             "Tick Box"
Question 5                "Tick Box"             "Tick Box"
Question 6                "Tick Box"             "Tick Box"

if(SSI_GetValue("YourQuestion_c1") == SSI_GetValue("YourQuestion_c2"))
{   strErrorMessage = "You can't choose the same thing in both rows.  Please review your answers and try again."; }

Is that right ( p.s.  I am using version 6.6.18 ) to put the above script into "Advanced"? How's about if it is in radio box?

Many thanks.
answered Nov 18, 2011 by anonymous
0 votes
Generaly, this is the good possibulity. But please note:
1. You can use this code only in advanced -> custom java script verification because other located script will run only once.
2. For "Tick boxes" in grid  (multiple variables) the condition will be
((SSI_GetValue("YourQuestion_r1_c1") == SSI_GetValue("YourQuestion_r1_c2") ) ||
((SSI_GetValue("YourQuestion_r2_c1") == SSI_GetValue("YourQuestion_r2_c2") ) ||
((SSI_GetValue("YourQuestion_r3_c1") == SSI_GetValue("YourQuestion_r3_c2") ) || .. ets

It is the same thing that Marion suggest ..
for grid format with checkboxes:
var R1C1 = SSI_GetValue("test_r1_c1");
var R1C2 = SSI_GetValue("test_r1_c2");
... r2  r3  ets

for raws grid format with radio buttons
var R1 = SSI_GetValue("test_r1");
var R2 = SSI_GetValue("test_r2");

for comums grid format with radio buttons
var C1 = SSI_GetValue("test_c1");
var C2 = SSI_GetValue("test_c2");


This must work both in 6 & 7.
answered Nov 18, 2011 by Dmitry Naletov (235 points)
edited Nov 18, 2011 by Dmitry Naletov
Hi all,

I tried some of the solutions above - thank you:

<script type="text/javascript">  
 <!--
function SSI_CustomGraphicalRadiobox(GraphicalRadioboxObj, InputObj)   
{
var Raw1 = SSI_GetValue("m1_r1");
var Raw2 = SSI_GetValue("m1_r2");
if (Raw1 == Raw2) {
    InputObj.checked = false;
        //InputObj.value =0;
    GraphicalRadioboxObj.removeClass("radioboxselected");
    GraphicalRadioboxObj.addClass("radiobox");
}
}
 //-->
</script>

My question name is 'm1'. In the first instance I can't select two simultaneously, but after 1 attempt the grid allows me to select it (i.e. on the second attempt). The later solution (from Dmitry Naletov), I am not sure how to implement. I would appreciate it if you let me know where to put the script and how it needs to look like. Do I put in the global settings header area like so?:

<script>
((SSI_GetValue("m1_c1_r1") == SSI_GetValue("m1_r1") ) ||
((SSI_GetValue("m1_c1_r2") == SSI_GetValue("m1_r2") ) ||
</script>

Many thanks,

Nadia
The blocking script
<script type="text/javascript">  
 <!--
function SSI_CustomGraphicalRadiobox(GraphicalRadioboxObj, InputObj)   
{
var Raw1 = SSI_GetValue("m1_r1");
var Raw2 = SSI_GetValue("m1_r2");
if (Raw1 == Raw2) {
    InputObj.checked = false;
        //InputObj.value =0;
    GraphicalRadioboxObj.removeClass("radioboxselected");
    GraphicalRadioboxObj.addClass("radiobox");
}
}
 //-->
</script>

must be in question footer or header  for grid or any other standart form or in the freeformat html but not in the global header.

>In the first instance I can't select two simultaneously, but after 1 attempt the grid allows me to select it (i.e. on the second attempt).
Very strange/ in my test project V7 with graphical buttons it works perfect. For V6 or for V7 without graphicall buttons you must use another  syntax - something like:
<script type="text/javascript">  
 <!--
document.mainform["m1_r1"].onchange = check;
document.mainform["m1_r2"].onchange = check;

function check()   
{
var Raw1 = SSI_GetValue("m1_r1");
var Raw2 = SSI_GetValue("m1_r2");
if (Raw1 == Raw2) {
SSI_Getobject("m1_r1").checked = false;
SSI_Getobject("m1_r2").checked = false;
}
}
 //-->
</script>
The script for verifying (after tne next button)
if (SSI_GetValue("m1_r1") == SSI_GetValue("m1_r2"))
{   
strErrorMessage = "You can't choose the same thing in both rows.  Please review your answers and try again.";
}

must be in the advanced->custom java script verification
please note - you must NOT use <script></script> and <!--  //--> tags in this section.
...