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

From Catglobe Wiki
Jump to: navigation, search
 
Line 13: Line 13:
 
{| border="0"
 
{| border="0"
 
|-
 
|-
| align="center" | &lt;img src="/images/a/a3/OneColumnBefore.JPG" _fck_mw_filename="OneColumnBefore.JPG" alt="" /&gt;<br/>
+
| align="center" | [[File:OneColumnBefore.JPG|none]]<br/>
| &lt;img src="/images/0/08/MultiColumnBefore.JPG" _fck_mw_filename="MultiColumnBefore.JPG" alt="" /&gt;
+
| [[File:MultiColumnBefore.JPG|none]]<br/>
 
|}
 
|}
  
Line 21: Line 21:
 
{|
 
{|
 
|-
 
|-
| align="center" | &lt;img src="/images/2/2f/OneColumnAfter.jpg" _fck_mw_filename="OneColumnAfter.jpg" alt="" /&gt;
+
| align="center" | [[File:OneColumnAfter.jpg|none]]<br/>
| &lt;img src="/images/6/69/MultiColumnAfter.jpg" _fck_mw_filename="MultiColumnAfter.jpg" alt="" /&gt;
+
| [[File:MultiColumnAfter.jpg|none]]<br/>
 
|}
 
|}
  
Line 30: Line 30:
 
*Go to menu Properties -> Question scripts -> Java script tab -> Input script
 
*Go to menu Properties -> Question scripts -> Java script tab -> Input script
  
&lt;img src="/images/5/56/AddTextBeforeAOOfSingleQuestion.jpg" _fck_mw_filename="AddTextBeforeAOOfSingleQuestion.jpg" alt="" /&gt;
+
[[File:AddTextBeforeAOOfSingleQuestion.jpg|none]]
  
 
== Code ==
 
== Code ==

Latest revision as of 04:27, 17 October 2013

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
AddTextBeforeAOOfSingleQuestion.jpg

Code

quest.insertTextBefore = function(aoIndex, text)
{
 var that = this;
 $(".option_row").each(
 function(i)
 {
 if (i == aoIndex)
 {
 var tr = $("<tr>").addClass("customized_text")
 .append($("<td>").text(text).attr("colSpan",that.cols)); 
 $(this).before(tr);
 }
 }
 );

}

quest.onInit = function()
{
 var text = "My Text";
 this.insertTextBefore(2, text);
}

Question stylesheet

.customized_text
{
 background-color:white;
}

Source

Questionnaire Resource Id on cg site: 159730

Question: Q_OS_Single_AddTextBeforeAO