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

From Catglobe Wiki
Jump to: navigation, search
Line 3: Line 3:
 
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.  
  
 +
<source lang="javascript" line="1">
 
option.prototype.getHTML = function(ltype) {  
 
option.prototype.getHTML = function(ltype) {  
  
Line 149: Line 150:
 
}  
 
}  
  
}<br><br>
+
}</source>

Revision as of 09:40, 2 March 2009

Chalenge :

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 
  5 if(this.visible) { 
  6 
  7 switch(ltype) { 
  8 
  9 case 2: 
 10 
 11 stmp += "&lt;input type=\"radio\" "; 
 12 
 13 stmp += "name=\""+this.label+"\" "; 
 14 
 15 stmp += "value=\""+this.value+"\" "; 
 16 
 17 if(this.checked) stmp += "checked "; 
 18 
 19 if(this.disabled) stmp += "disabled "; 
 20 
 21 stmp += "onclick=\"myoptclick('"+this.label+"',"+this.index+",false);\"&gt;"; 
 22 
 23 return "&lt;td valign=\"center\" align=\""+this.align+"\"&gt;"+stmp+"&lt;/td&gt;";; 
 24 
 25 break; 
 26 
 27 } 
 28 
 29 } 
 30 
 31 } 
 32 
 33 quest.next = nextTest; 
 34 
 35 function nextTest() { 
 36 
 37 // initialise check array 
 38 
 39 var arrIndexUsed = new Array(); 
 40 
 41 for (i=0;i&lt;quest.questions[0].options.length;i++) { 
 42 
 43 arrIndexUsed[i] = false; 
 44 
 45 } 
 46 
 47 // loop through options and check for double used options 
 48 
 49 for (i=0;i&lt;quest.questions.length;i++) { 
 50 
 51 for (j=0;j&lt;quest.questions[i].options.length;j++) { 
 52 
 53 if (quest.questions[i].options[j].checked) { 
 54 
 55 arrIndexUsed[j] = true; 
 56 
 57 } 
 58 
 59 } 
 60 
 61 } 
 62 
 63 // loop through possible answer options and check that all are used 
 64 
 65 for (i=0;i&lt;arrIndexUsed.length;i++) { 
 66 
 67 if (&nbsp;! arrIndexUsed[i] ) { 
 68 
 69 alert('All options must used'); 
 70 
 71 return false; 
 72 
 73 } 
 74 
 75 } 
 76 
 77 buttonsStatus(true); 
 78 
 79 document["query"]["dir"].value = "next"; 
 80 
 81 return true; 
 82 
 83 } 
 84 
 85 function myoptclick(slbl, lidx, blnk) { 
 86 
 87 optclick(slbl, lidx, blnk); 
 88 
 89 for (i=0;i&lt;quest.questions.length;i++) { 
 90 
 91 if ( quest.questions[i].label&nbsp;!= slbl ) { 
 92 
 93 quest.questions[i].options[lidx].checked = false; 
 94 
 95 o1 = document["query"][quest.questions[i].label]; 
 96 
 97 cb = o1; 
 98 
 99 cb[lidx].checked = false; 
100 
101 } 
102 
103 else { 
104 
105 for (j=0;j&lt;quest.questions[i].options.length;j++) { 
106 
107 quest.questions[i].options[j].checked = false; 
108 
109 } 
110 
111 quest.questions[i].options[lidx].checked = true; 
112 
113 o1 = document["query"][quest.questions[i].label]; 
114 
115 cb = o1; 
116 
117 cb[lidx].checked = true; 
118 
119 } 
120 
121 } 
122 
123 }