Welcome to the LimeSurvey Community Forum

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

Assign Answer from Array to a Category

  • michaelji
  • michaelji's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
7 years 10 months ago #137183 by michaelji
Assign Answer from Array to a Category was created by michaelji
Can I and, how can I assign an array answer to a category in order to tally the category?

The respondent chooses column 2 in the array for Option 1. I want to assign Category 3 with a value of 2.

Next question, similar, chooses column 5 for Option 3. This should be assigned Category 1with a value of 5.

The goal is to report to the admin that this respondent rates in Category 1, so far
And better yet, report to the admin the score of the four categories to the admin in the "Detailed admin notification"

Thanks

tpartner wrote: I'm still not convinced this is the best design but you could do something like this:

Code:
<script type="text/javascript" charset="utf-8">  
 
  $(document).ready(function(){  
 
    // Identify this question
    var thisQuestion = $('#question{QID}');
 
    // Assign column-specific classes
    $('table.subquestion-list tr', thisQuestion).each(function(i) {
 
      var scale = 1;
      $('> *:gt(0)', this).each(function(i){
        $(this).addClass('column-'+(i+1)+' scale-'+scale+'');
        $(this).attr('data-column', i+1);
        $(this).attr('data-scale', scale);
        if(i == 1) {
          scale++
        }
      });
    });
 
    // Listener on the radios
    $('input.radio', thisQuestion).on('click', function(e){
      $('input.radio', thisQuestion).prop('disabled', false);
      $('input.radio:checked', thisQuestion).each(function(e) {
        var thisCell = $(this).closest('td.answer-item');
        var thisScale = $(thisCell).attr('data-scale');
        $('td[data-scale="'+thisScale+'"]', thisQuestion).not(thisCell).find('input.radio').prop('disabled', true);
      });
    });
 
    // Insert scale headers and separator
    $('colgroup', thisQuestion).remove();
    $('.scale-1.column-1', thisQuestion).before('<td class="inserted-scale-separator"></td>');
    $('.scale-1.column-2', thisQuestion).after('<td class="inserted-scale-separator"></td>');
    $('table.subquestion-list thead', thisQuestion).prepend('<tr class="scale-headers">\
                                  <td></td>\
                                  <td class="inserted-scale-separator"></td>\
                                  <th class="text-center scale-1" data-scale="1" colspan="2">Scale 1</th>\
                                  <td class="inserted-scale-separator"></td>\
                                  <th class="text-center scale-2" data-scale="2" colspan="2">Scale 2</th>\
                                </tr>');
 
    // Some styles (could be done in template.css)
    $('.inserted-scale-separator', thisQuestion).css({
      'width': '5px',
      'background-color': '#FFFFFF'
    });
    $('thead .scale-1', thisQuestion).css({
      'background-color': '#8da6c1',
      'font-weight': 'bold'
    });
    $('thead .scale-2', thisQuestion).css({
      'background-color': '#a7bacf',
      'font-weight': 'bold'
    });
    $('tbody .scale-1', thisQuestion).css({
      'background-color': '#c0cedd',
      'font-weight': 'bold'
    });
    $('tbody .scale-2', thisQuestion).css({
      'background-color': '#dae2eb',
      'font-weight': 'bold'
    });
 
    // Insert a "Reset" button
    $('table.subquestion-list', thisQuestion).after('<input type="button" style="float:right;" value="Reset Question" class="resetQuestionButton" />');
 
    $('.resetQuestionButton', thisQuestion).click(function(e){
      $('input.radio', thisQuestion).prop('checked', false);
      $('input.radio', thisQuestion).prop('disabled', false);
    });
  });
</script>




Sample survey attached:

File Attachment:

File Name: limesurvey...9829.lss
File Size:18 KB

The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 10 months ago #137202 by tpartner
Replied by tpartner on topic Assign Answer from Array to a Category
Please do not ask the same question in multiple threads. If someone had an answer, they would have given it.

I suspect you can achieve what you want with equation type questions if you read the Expression Manager documentation.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • michaelji
  • michaelji's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
7 years 10 months ago #137228 by michaelji
Replied by michaelji on topic Assign Answer from Array to a Category
Sorry for the cross post...I cannot edit the original and the typo error. I figured that people could not search on a misspelled topic heading.

I will check the suggestion you made and plow through the manual for my answer. I thought it would be an easy answer to and easy question. Limesurvey, since it is group effort is difficult at times to figure out. The manual references the older version and older interface, so I have to try and interpret what is being described in relation to the new menus and interface.

BTW, thanks for the answer/suggestion, rant aside...
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose