Difference between revisions of "Both horizontal and vertical single grid"

From Catglobe Wiki
Jump to: navigation, search
(New page: Chalenge : There are a single grid question . Respondents should prioritize statements (sub questions) . <br>Example : I have a list of trade-mark and want the user to prio...)
 
 
(5 intermediate revisions by one other user not shown)
Line 1: Line 1:
Chalenge&nbsp;:  
+
== Challenge&nbsp;: ==
  
There are a single grid question . Respondents should prioritize statements (sub questions) .  
+
There are a single grid question . Respondents should prioritize statements (sub questions) .
  
<br>Example&nbsp;:  
+
== <br>Example&nbsp;: ==
  
 
I have a list of trade-mark and want the user to prioritize those list&nbsp;:  
 
I have a list of trade-mark and want the user to prioritize those list&nbsp;:  
Line 17: Line 17:
 
[[Image:Example 1.JPG]]<br>  
 
[[Image:Example 1.JPG]]<br>  
  
<br>Solution&nbsp;:  
+
== <br>Solution&nbsp;: ==
  
 
Use single grid question (statements as subquestion and ranks as answer option )  
 
Use single grid question (statements as subquestion and ranks as answer option )  
Line 23: Line 23:
 
<br>  
 
<br>  
  
Code  
+
== Code ==
  
 
The script makes a single grid question function as a single grid both horizontally and vertically.  
 
The script makes a single grid question function as a single grid both horizontally and vertically.  
  
option.prototype.getHTML = function(ltype) {  
+
<source lang="javascript" line="1">
 +
option.prototype.getHTML = function(ltype)
 +
{
 +
  var stmp = "";
 +
  if (this.visible)
 +
  {
 +
      switch (ltype)
 +
      {
 +
        case 2:
 +
            stmp += "<input type=\"radio\" ";
 +
            stmp += "name=\"" + this.label + "\" ";
 +
            stmp += "value=\"" + this.value + "\" ";
 +
            if (this.checked)
 +
              stmp += "checked ";
 +
            if (this.disabled)
 +
              stmp += "disabled ";
 +
            stmp += "onclick=\"myoptclick('" + this.label + "'," + this.index + ",false);\">";
 +
            return "<td valign=\"center\" align=\"" + this.align + "\">" + stmp + "</td>"; ;
 +
            break;
 +
      }
 +
  }
 +
}
 +
quest.next = nextTest;
 +
function nextTest()
 +
{
 +
  // initialise check array
 +
  var arrIndexUsed = new Array();
 +
  for (i = 0; i < quest.questions[0].options.length; i++)
 +
      arrIndexUsed[i] = false;
 +
  // loop through options and check for double used options
 +
  for (i = 0; i < quest.questions.length; i++)
 +
  {
 +
      for (j = 0; j < quest.questions[i].options.length; j++)
 +
      {
 +
        if (quest.questions[i].options[j].checked)
 +
            arrIndexUsed[j] = true;
 +
      }
 +
  }
 +
  // loop through possible answer options and check that all are used
 +
  for (i = 0; i < arrIndexUsed.length; i++)
 +
  {
 +
      if (!arrIndexUsed[i])
 +
      {
 +
        alert('All options must used');
 +
        return false;
 +
      }
 +
  }
 +
  buttonsStatus(true);
 +
  document["query"]["dir"].value = "next";
 +
  return true;
 +
}
 +
function myoptclick(slbl, lidx, blnk)
 +
{
 +
  optclick(slbl, lidx, blnk);
 +
  for (i = 0; i < quest.questions.length; i++)
 +
  {
 +
      if (quest.questions[i].label != slbl)
 +
      {
 +
        quest.questions[i].options[lidx].checked = false;
 +
        o1 = document["query"][quest.questions[i].label];
 +
        cb = o1;
 +
        cb[lidx].checked = false;
 +
      }
 +
      else
 +
      {
 +
        for (j = 0; j < quest.questions[i].options.length; j++)
 +
            quest.questions[i].options[j].checked = false;
 +
        quest.questions[i].options[lidx].checked = true;
 +
        o1 = document["query"][quest.questions[i].label];
 +
        cb = o1;
 +
        cb[lidx].checked = true;
 +
      }
 +
  }
 +
}
 +
</source>
 +
== Source ==
  
var stmp = "";
+
Questionnaire Resource Id on cg.catglobe.com site: 164079 (Question: Q3_Both_horizontal_and_vertical_single_grid)
 
 
if(this.visible) {
 
 
 
switch(ltype) {
 
 
 
case 2:  
 
 
 
stmp += "&lt;input type=\"radio\" ";
 
 
 
stmp += "name=\""+this.label+"\" ";
 
 
 
stmp += "value=\""+this.value+"\" ";
 
 
 
if(this.checked) stmp += "checked ";
 
 
 
if(this.disabled) stmp += "disabled ";
 
 
 
stmp += "onclick=\"myoptclick('"+this.label+"',"+this.index+",false);\"&gt;";
 
 
 
return "&lt;td valign=\"center\" align=\""+this.align+"\"&gt;"+stmp+"&lt;/td&gt;";;
 
 
 
break;
 
 
 
}
 
 
 
}
 
 
 
}
 
 
 
quest.next = nextTest;
 
 
 
function nextTest() {
 
 
 
// initialise check array
 
 
 
var arrIndexUsed = new Array();
 
 
 
for (i=0;i&lt;quest.questions[0].options.length;i++) {
 
 
 
arrIndexUsed[i] = false;
 
 
 
}
 
 
 
// loop through options and check for double used options
 
 
 
for (i=0;i&lt;quest.questions.length;i++) {
 
 
 
for (j=0;j&lt;quest.questions[i].options.length;j++) {
 
 
 
if (quest.questions[i].options[j].checked) {
 
 
 
arrIndexUsed[j] = true;
 
 
 
}
 
 
 
}
 
 
 
}
 
 
 
// loop through possible answer options and check that all are used
 
 
 
for (i=0;i&lt;arrIndexUsed.length;i++) {
 
 
 
if (&nbsp;! arrIndexUsed[i] ) {
 
 
 
alert('All options must used');
 
 
 
return false;
 
 
 
}
 
 
 
}
 
 
 
buttonsStatus(true);
 
 
 
document["query"]["dir"].value = "next";
 
 
 
return true;
 
 
 
}
 
 
 
function myoptclick(slbl, lidx, blnk) {
 
 
 
optclick(slbl, lidx, blnk);
 
 
 
for (i=0;i&lt;quest.questions.length;i++) {
 
 
 
if ( quest.questions[i].label&nbsp;!= slbl ) {
 
 
 
quest.questions[i].options[lidx].checked = false;
 
 
 
o1 = document["query"][quest.questions[i].label];
 
 
 
cb = o1;
 
 
 
cb[lidx].checked = false;
 
 
 
}
 
 
 
else {
 
 
 
for (j=0;j&lt;quest.questions[i].options.length;j++) {
 
 
 
quest.questions[i].options[j].checked = false;
 
 
 
}
 
 
 
quest.questions[i].options[lidx].checked = true;
 
 
 
o1 = document["query"][quest.questions[i].label];
 
 
 
cb = o1;
 
 
 
cb[lidx].checked = true;
 
 
 
}
 
 
 
}
 
 
 
}<br><br>
 

Latest revision as of 08:05, 3 February 2012

Challenge :

There are a single grid question . Respondents should prioritize statements (sub questions) .


Example :

I have a list of trade-mark and want the user to prioritize those list :

Dell

Apple

IBM

FPT Elead

Example 1.JPG


Solution :

Use single grid question (statements as subquestion and ranks as answer option )


Code

The script makes a single grid question function as a single grid both horizontally and vertically.

 1 option.prototype.getHTML = function(ltype)
 2 {
 3    var stmp = "";
 4    if (this.visible)
 5    {
 6       switch (ltype)
 7       {
 8          case 2:
 9             stmp += "<input type=\"radio\" ";
10             stmp += "name=\"" + this.label + "\" ";
11             stmp += "value=\"" + this.value + "\" ";
12             if (this.checked)
13                stmp += "checked ";
14             if (this.disabled)
15                stmp += "disabled ";
16             stmp += "onclick=\"myoptclick('" + this.label + "'," + this.index + ",false);\">";
17             return "<td valign=\"center\" align=\"" + this.align + "\">" + stmp + "</td>"; ;
18             break;
19       }
20    }
21 }
22 quest.next = nextTest;
23 function nextTest()
24 {
25    // initialise check array
26    var arrIndexUsed = new Array();
27    for (i = 0; i < quest.questions[0].options.length; i++)
28       arrIndexUsed[i] = false;
29    // loop through options and check for double used options
30    for (i = 0; i < quest.questions.length; i++)
31    {
32       for (j = 0; j < quest.questions[i].options.length; j++)
33       {
34          if (quest.questions[i].options[j].checked)
35             arrIndexUsed[j] = true;
36       }
37    }
38    // loop through possible answer options and check that all are used
39    for (i = 0; i < arrIndexUsed.length; i++)
40    {
41       if (!arrIndexUsed[i])
42       {
43          alert('All options must used');
44          return false;
45       }
46    }
47    buttonsStatus(true);
48    document["query"]["dir"].value = "next";
49    return true;
50 }
51 function myoptclick(slbl, lidx, blnk)
52 {
53    optclick(slbl, lidx, blnk);
54    for (i = 0; i < quest.questions.length; i++)
55    {
56       if (quest.questions[i].label != slbl)
57       {
58          quest.questions[i].options[lidx].checked = false;
59          o1 = document["query"][quest.questions[i].label];
60          cb = o1;
61          cb[lidx].checked = false;
62       }
63       else
64       {
65          for (j = 0; j < quest.questions[i].options.length; j++)
66             quest.questions[i].options[j].checked = false;
67          quest.questions[i].options[lidx].checked = true;
68          o1 = document["query"][quest.questions[i].label];
69          cb = o1;
70          cb[lidx].checked = true;
71       }
72    }
73 }

Source

Questionnaire Resource Id on cg.catglobe.com site: 164079 (Question: Q3_Both_horizontal_and_vertical_single_grid)