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

From Catglobe Wiki
Jump to: navigation, search
m (Code)
(uestion to Question)
Line 24: Line 24:
 
|}
 
|}
  
== Solution ==
+
== Solution ==
 
+
*Add a Single question to Questionaire editor
Find the index of the row in single question , and add new text before it .
+
*Go to menu Properties -> Question scripts -> Java script tab -> Input script
  
 
== Code  ==
 
== Code  ==
Line 62: Line 62:
 
}
 
}
 
</source>
 
</source>
 +
 +
==Source==
 +
Questionnaire Resource Id on cg site: 159730
 +
Question: Q_OS_Single_AddTextBeforeAO

Revision as of 08:46, 3 February 2012

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.

OneColumnBefore.JPG MultiColumnBefore.JPG


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

OneColumnAfter.jpg MultiColumnAfter.jpg

Solution

  • Add a Single question to Questionaire editor
  • Go to menu Properties -> Question scripts -> Java script tab -> Input script

Code

 1 quest.insertTextBefore = function(aoIndex, text)
 2 {
 3 	var that = this;
 4 	$(".option_row").each(
 5 		function(i)
 6 		{
 7 			if (i == aoIndex)
 8 			{
 9 				var tr = $("<tr>").addClass("customized_text")
10 						.append($("<td>").text(text).attr("colSpan",that.cols)); 
11 				$(this).before(tr);
12 			}
13 		}
14 	);
15 
16 }
17 
18 quest.onInit = function()
19 {
20    var text = "My Text";
21 	this.insertTextBefore(2, text);
22 }

Question stylesheet

.customized_text
{
   background-color:white;
}

Source

Questionnaire Resource Id on cg site: 159730 Question: Q_OS_Single_AddTextBeforeAO