Difference between revisions of "Show a text grid and a single question in the same page"

From Catglobe Wiki
Jump to: navigation, search
Line 1: Line 1:
<source lang="javascript" line="1">
+
= Show a text grid and a single question in the same page =
var SingleQuestion = {
 
onInit: function(_label, _answerOptionValues, _answerOptionTexts)
 
{
 
this.label = "QUESTION." + _label;
 
this.aoValues = _answerOptionValues;
 
this.aoTexts = _answerOptionTexts;
 
this.selectedValue = "";
 
},
 
optClick: function(value)
 
{
 
if (this.selectedValue == value)//click the checkbox twice => unchecked
 
{
 
this.selectedValue = "";
 
$("input:text").attr("disabled", "");
 
$("input:checkbox").attr("checked", "");
 
}
 
else
 
{
 
//disable all other inputs
 
this.selectedValue = value;
 
$("input:text").attr("disabled", "disabled");
 
 
$("input:checkbox").each(
 
function(i)
 
{
 
if ($(this).val() == value)
 
$(this).attr("checked", "checked");
 
else
 
$(this).attr("checked", "");
 
}
 
);
 
}
 
},
 
getHTML: function()
 
{
 
var t = $("<table>");
 
var n = this.aoValues.length;
 
for (var i = 0; i<n; i++)
 
{
 
t.append(this.getHTML_AO(i));
 
}
 
t.append($("<input type = \"hidden\">").attr("name", this.label).val(""));
 
return t;
 
},
 
getHTML_AO: function(index)
 
{
 
var value = this.aoValues[index];
 
var text = this.aoTexts[index];
 
return $("<tr>")
 
.append(
 
$("<td>").width("16px").attr("valign", "top")
 
.append(
 
$("<input type=\"checkbox\">").attr("name", this.label).val(value).click(
 
function()
 
{
 
SingleQuestion.optClick(value);
 
}
 
)
 
)
 
)
 
.append(
 
$("<td>").append($("<a class=\"option_link\" href=\"javascript:SingleQuestion.optClick(" + value + ");\">" + text + "</a>"))
 
);
 
}
 
}
 
  
var TextGridQuestion =
+
In order to allow the respondent to skip a text grid question
{
 
onInit: function(_quest)
 
{
 
this.quest = _quest;
 
},
 
questionCheck: function()
 
{
 
acont = new Array();
 
    msg = "";
 
    cont = true;
 
  
for (i=0; i < this.quest.questions.length; i++)
+
As a questionnaire creator
acont[i] = (trim(document["query"][this.quest.questions[i].label].value) != "");
 
  
msg = this.quest.ingridrequiredtext+"\n";
+
I want to show several options at the end of a text grid question, on which the respondents can click to skip the text grid question. This is similar to question of Open type.
for (i = 0; i < this.quest.questions.length; i++)
 
{
 
// If the sub question is not visible or answering this
 
// sub question is not answered and not required to be
 
// then we continue with the next sub question
 
if(!this.quest.questions[i].visible || (!this.quest.questions[i].required && !acont[i]))
 
continue;
 
  
if(this.quest.questions[i].required && !acont[i])
+
[[Image:QuestionTips_TextGrid_Enabled.jpg]]  
{
 
tmp = this.quest.questions[i].text;
 
tmp = tmp.replace(/(<!\-\-|\-\->)/ig, "");
 
tmp = tmp.replace(/&nbsp;/ig, " ");
 
msg += " - '"+trim(tmp.replace(/<[^>]*>/ig, ""))+"'\n";
 
cont = false;
 
continue;
 
}
 
}
 
  
if (!cont)
+
[[Image:QuestionTips_TextGrid_Disabled.jpg]]
{
 
ErrorMessages.getInstance().showErrorMessage(msg);
 
return false;
 
}
 
return true;
 
}
 
}
 
 
 
this.questioncheck = function()
 
{
 
ErrorMessages.getInstance().clearErrorMessages();
 
if (SingleQuestion.selectedValue != "")
 
return true;
 
 
return TextGridQuestion.questionCheck();
 
}
 
 
 
quest.onInit = function()
 
{
 
var single = "{{Single.Value}}";
 
var aoV = new Array();
 
aoV[0] = 1;
 
aoV[1] = 2;
 
var aoT = new Array();
 
aoT[0] = "I do not want to give those information";
 
aoT[1] = "I do not have time for this"
 
SingleQuestion.onInit("Single", aoV, aoT);
 
 
//look for the outer grid
 
$(".grid_outer").append(
 
$("<tr>").css("background-color", "white").append($("<td>").append(SingleQuestion.getHTML()))
 
);
 
 
if (single != "")
 
{
 
SingleQuestion.optClick(single);
 
}
 
 
TextGridQuestion.onInit(this);
 
$("input:text").width("200px");
 
}
 
</source>
 

Revision as of 08:25, 18 December 2008

Show a text grid and a single question in the same page

In order to allow the respondent to skip a text grid question

As a questionnaire creator

I want to show several options at the end of a text grid question, on which the respondents can click to skip the text grid question. This is similar to question of Open type.

QuestionTips TextGrid Enabled.jpg

QuestionTips TextGrid Disabled.jpg