Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

5-linkert Triple scale array question with rows that can be added

  • Minh1987
  • Minh1987's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 days 5 hours ago - 2 days 6 hours ago #269269 by Minh1987
     [object Object]

I'm using Limesurvey Cloud.
What should I do to have a question like above? I am a new user and have no idea on Javascript or similar.

Thanks so much in advance for your help.
Last edit: 2 days 6 hours ago by Minh1987.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 day 5 hours ago #269318 by Joffm
Hi,
to achieve this you can use an array(numbers) question with three dropdowns.
 

If you would like to display "better" scales than 1,2,3,... you may use an array(text) with dropdowns.
There are dozens of examples in the forum, e.g.
[url] forums.limesurvey.org/forum/can-i-do-thi...cific-columns#226861 [/url]
 

And for your "Other" option there are dozens of examples as well.
Like
[url] forums.limesurvey.org/forum/can-i-do-thi...rray?start=12#255730 [/url]

Joffm

If you'd provided a lss export of these relevant questions we could have helped better.

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

  • Minh1987
  • Minh1987's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
12 hours 42 minutes ago - 11 hours 56 minutes ago #269336 by Minh1987
 

File Attachment:

File Name: limesurvey...6754.lss
File Size:59 KB
 

Thanks for your instruction. I have copied both codes and pasted but there maybe something wrong. The added rows doesn't work.. Could you please tell me how I can do?
Last edit: 11 hours 56 minutes ago by Minh1987.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
10 hours 24 minutes ago #269341 by Joffm
Hi,
What for is a script in the first subquestion text?
What for is the condition in the "Other" subquestions?
Do you want to pipe in something?
There are subquestion conditions that refer to the NEXT subquestion? What is the reason for this?

If I remove everything mentioned above, split the two scripts and start the first with
  $(document).ready(function() { 

everything is fine
 

So please revise.

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

  • Minh1987
  • Minh1987's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
9 hours 52 minutes ago - 9 hours 37 minutes ago #269345 by Minh1987
 

File Attachment:

File Name: limesurvey...7541.lss
File Size:59 KB

Thanks for your quick instruction. I revised and it work. However, there is still a bit mistake.
I intended to imitate the instruction in the following link: forums.limesurvey.org/forum/can-i-do-thi...rray?start=12#255730
I want the other 2 only appear after the respondent typed Other 1.
In this case, all appear at the same time..
Last edit: 9 hours 37 minutes ago by Minh1987.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 hours 44 minutes ago - 3 hours 52 minutes ago #269349 by Joffm

However, there is still a bit mistake.

No, it is not.
As you see the script runs when the page is loaded
$(document).ready(function() { 
This means it doesn't take into account what happened before.

You have to rethink your design.

I could propose:
  • Use an array text with four columns
  • Preset the first column of row 1 and row 2 by an expression
  • Disable these two fields
  • Optionally enter a header for the "Others"
  • Show the next "Other" row, if the count of the previous row is equal to 4.






Scripts:
To enter the dropdowns you have to use a different script that takes in account the used columns (no dropdown in the first column)
Code:
<script type="text/javascript" charset="utf-8">
  $(document).on('ready pjax:scriptcomplete',function(){
    var thisQuestion = $('#question{QID}');
 
    // Insert selects
    $('.answer-item.answer_cell_X002', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\
  <option value="">Please choose...</option>\
<option value="1">very low</option>\
<option value="2">low</option>\
<option value="3">medium</option>\
<option value="4">good</option>\
<option value="5">very good</option>\
    </select>');
    $('.answer-item.answer_cell_X003', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\
 <option value="">Please choose...</option>\
<option value="1">very low</option>\
<option value="2">low</option>\
<option value="3">medium</option>\
<option value="4">good</option>\
<option value="5">very good</option>\
    </select>');  
    $('.answer-item.answer_cell_X004', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\
 <option value="">Please choose...</option>\
<option value="1">very low</option>\
<option value="2">low</option>\
<option value="3">medium</option>\
<option value="4">good</option>\
<option value="5">very good</option>\
    </select>');
 
   // Listeners
    $('.inserted-select', thisQuestion).on('change', function(i) {
      if($(this).val() != '') {
        $(this).closest('.answer-item').find('input:text').val($('option:selected', this).val()).trigger('change');
      }
      else {
        $(this).closest('.answer-item').find('input:text').val('').trigger('change');
      }
    });
     // Returning to page
    $('.with-select input:text', thisQuestion).each(function(i) {
      var thisCell = $(this).closest('.answer-item');
      var inputText = $.trim($(this).val());
      $('select.inserted-select', thisCell).val(inputText);
    });
 
   // Clean-up styles
    $('select.inserted-select', thisQuestion).css({
      'max-width': '100%'
    });
    $('.with-select input:text', thisQuestion).css({
      'position': 'absolute',
      'left': '-9999em'
    });
  });
</script>


To disable the two fields
Code:
<script type="text/javascript" charset="utf-8">
  $(document).on('ready pjax:scriptcomplete',function(){
    $("#answer{SGQ}Y001_X001").prop('disabled', true);
    $("#answer{SGQ}Y002_X001").prop('disabled', true);
  });
</script>


To insert the additional header
Code:
<script type="text/javascript" charset="utf-8">        
    $(document).ready(function() {
       // Identify this question
      var thisQuestion = $('#question{QID}');
      // Define the sub-heading text strings
      var subHeading1 = '<span style="color:maroon;font-size:12pt;font-weight:bold">Others (optional)</span>';
      var columnsLength = $('tr.subquestion-list:eq(0) > *', thisQuestion).length;
        // Insert the new rows
        $('tr.subquestion-list:eq(2)', thisQuestion).before('<tr class="sub-header-row"><th colspan="'+columnsLength+'">'+subHeading1+'</th></tr>');
        // Fix up the row classes
      var rowClass = 1;
      $('table.subquestions-list tbody tr', thisQuestion).each(function(i) {
            if($(this).hasClass('sub-header-row')) {
                rowClass = 1
            }
            else {
                rowClass++;
            $(this).removeClass('array1 array2')
            if(rowClass % 2 == 0) {
                $(this).addClass('array2');
            }
            else {
                $(this).addClass('array1');
                }
            }
        });
    });
</script>


And to preset the two fields 

{Q2_Y001_X001='Employee 1'}
{Q2_Y002_X001='Employee 2'}


Joffm
 

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 3 hours 52 minutes ago by Joffm.

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose