Toggle menu
862
3.8K
30.2K
279.1K
Catglobe Wiki
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Convert closed question TextBox into TextArea

From Catglobe Wiki
Revision as of 04:06, 6 February 2012 by Cg loc (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Challenge

In Single question or Multi Question, a textbox might not enough for respondent to give a long answer.
As a questionnaire creator
I want to convert a textbox into a textarea.


Example:

       =>       

Solution

  • Create a Single question or Multi Question
  • Give a option allow open answer
  • Add the below script to that question

Code

quest.onInit = function()
{
    $.each($("input[type='text']"), function()
    {
        var inputName = this.name;
        var inputValue = this.value;
        var answerOptionValue = inputName.slice(inputName.lastIndexOf(".") + 1);

        if ($("input[value='" + answerOptionValue + "']").attr("checked"))
            $(this).replaceWith("<textarea rows='8' cols='55' name='" + inputName + "'>" + inputValue + "</textarea>");
        else
            $(this).replaceWith("<textarea rows='8' cols='55' disabled = 'disabled'  name='" + inputName + "'>" + inputValue + "</textarea>");
    });
}

Source

Questionnaire Resource Id on cg.catglobe.com site: 164079 (Question: Q12_Convert_closed_question_TextBox_into_TextArea)