Both horizontal and vertical single grid

From Catglobe Wiki
Revision as of 10:40, 2 March 2009 by Catglobe (talk | contribs)
Jump to: navigation, search

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 += "<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);\">"; 
 22 
 23 return "<td valign=\"center\" align=\""+this.align+"\">"+stmp+"</td>";; 
 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<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<quest.questions.length;i++) { 
 50 
 51 for (j=0;j<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<arrIndexUsed.length;i++) { 
 66 
 67 if ( ! 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<quest.questions.length;i++) { 
 90 
 91 if ( quest.questions[i].label != 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<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 }