Difference between revisions of "Add text before answer option of single question"

From Catglobe Wiki
Jump to: navigation, search
(New page: == Challenge == In order to add text before answer option of single question As a questionnaire creator I want to add text before answer option of single question '''Example''' I have...)
 
(Code)
Line 24: Line 24:
  
 
<source lang="javascript" line="1">
 
<source lang="javascript" line="1">
quest.insertTextBefore = function(valueOfAnswerOption, text)
+
quest.insertTextBefore = function(aoIndex, text)
 
{
 
{
var inp = $(".option_table").find("input[value='"+valueOfAnswerOption+"']");
+
$(".option_row").each(
if(inp.length <= 0)
+
function(i)
return;
+
{
if(this.autoarrangeansweroptions != false && cols > 1)
+
if (i == aoIndex)
$("<tr><td class=\"answer_option_cell\" colspan=\"3\">"+text+"</td></tr>").insertBefore($(inp.parent().parent()));
+
{
else
+
var tr = $("<tr>").append($("<td>").text(text).addClass("customized_text"));
$("<tr><td class=\"answer_option_cell\">"+text+"</td></tr>").insertBefore($(inp.parent().parent().parent().parent().parent().parent()));
+
$(this).before(tr);
 +
}
 +
}
 +
);
 
}
 
}
  
 
quest.onInit = function()
 
quest.onInit = function()
 
{
 
{
this.insertTextBefore(8, "hello there!!");
+
  var text = "My Text";
        this.insertTextBefore(5, "hello there 2!!");
+
this.insertTextBefore(3, text);//insert the text before answer option index 3 (zero-based index)
 
}
 
}
 
</source>
 
</source>

Revision as of 11:38, 14 April 2009

Challenge

In order to add text before answer option of single question

As a questionnaire creator

I want to add text before answer option of single question

Example

I have a single question.

SingleAddtext.jpg

I want to add an text before answer option like this image

SingleAddtext2.jpg

Solution

Find the answer option in single question , and add new text before it .

Code

 1 quest.insertTextBefore = function(aoIndex, text)
 2 {
 3 	$(".option_row").each(
 4 		function(i)
 5 		{
 6 			if (i == aoIndex)
 7 			{
 8 				var tr = $("<tr>").append($("<td>").text(text).addClass("customized_text")); 
 9 				$(this).before(tr);
10 			}
11 		}
12 	);
13 }
14 
15 quest.onInit = function()
16 {
17    var text = "My Text";
18 	this.insertTextBefore(3, text);//insert the text before answer option index 3 (zero-based index)	
19 }