More actions
No edit summary |
|||
Line 28: | Line 28: | ||
<source lang="javascript" line="1"> | <source lang="javascript" line="1"> | ||
option.prototype.getHTML = function(ltype) { | option.prototype.getHTML = function(ltype) | ||
{ | |||
var stmp = ""; | var stmp = ""; | ||
if (this.visible) | |||
if(this.visible) { | { | ||
switch (ltype) | |||
switch(ltype) { | { | ||
case 2: | |||
case 2: | stmp += "<input type=\"radio\" "; | ||
stmp += "name=\"" + this.label + "\" "; | |||
stmp += " | stmp += "value=\"" + this.value + "\" "; | ||
if (this.checked) | |||
stmp += "name=\""+this.label+"\" "; | stmp += "checked "; | ||
if (this.disabled) | |||
stmp += "value=\""+this.value+"\" "; | stmp += "disabled "; | ||
stmp += "onclick=\"myoptclick('" + this.label + "'," + this.index + ",false);\">"; | |||
if(this.checked) stmp += "checked "; | return "<td valign=\"center\" align=\"" + this.align + "\">" + stmp + "</td>"; ; | ||
break; | |||
if(this.disabled) stmp += "disabled "; | } | ||
} | |||
stmp += "onclick=\"myoptclick('"+this.label+"',"+this.index+",false);\" | } | ||
quest.next = nextTest; | |||
return " | function nextTest() | ||
{ | |||
break; | // 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++) | |||
quest.next = nextTest; | { | ||
if (quest.questions[i].options[j].checked) | |||
function nextTest() { | arrIndexUsed[j] = true; | ||
} | |||
// initialise check array | } | ||
// loop through possible answer options and check that all are used | |||
var arrIndexUsed = new Array(); | for (i = 0; i < arrIndexUsed.length; i++) | ||
{ | |||
for (i=0;i | if (!arrIndexUsed[i]) | ||
{ | |||
arrIndexUsed[i] = false; | alert('All options must used'); | ||
return false; | |||
} | |||
} | |||
// loop through options and check for double used options | buttonsStatus(true); | ||
document["query"]["dir"].value = "next"; | |||
for (i=0;i | return true; | ||
} | |||
for (j=0;j | function myoptclick(slbl, lidx, blnk) | ||
{ | |||
if (quest.questions[i].options[j].checked) | optclick(slbl, lidx, blnk); | ||
for (i = 0; i < quest.questions.length; i++) | |||
arrIndexUsed[j] = true; | { | ||
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; | ||
} | |||
// loop through possible answer options and check that all are used | else | ||
{ | |||
for (i=0;i | for (j = 0; j < quest.questions[i].options.length; j++) | ||
quest.questions[i].options[j].checked = false; | |||
if ( | quest.questions[i].options[lidx].checked = true; | ||
o1 = document["query"][quest.questions[i].label]; | |||
alert('All options must used'); | cb = o1; | ||
cb[lidx].checked = true; | |||
return false; | } | ||
} | |||
} | |||
} | |||
buttonsStatus(true); | |||
document["query"]["dir"].value = "next"; | |||
return true; | |||
} | |||
function myoptclick(slbl, lidx, blnk) { | |||
optclick(slbl, lidx, blnk); | |||
for (i=0;i | |||
if ( quest.questions[i].label | |||
quest.questions[i].options[lidx].checked = false; | |||
o1 = document["query"][quest.questions[i].label]; | |||
cb = o1; | |||
cb[lidx].checked = false; | |||
} | |||
for (j=0;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> |
Revision as of 08:50, 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
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.
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;
}
}
}