Welcome to the LimeSurvey Community Forum

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

Matrix ( Numbers) with a usual Matrix?

  • StefanBasen
  • StefanBasen's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
8 years 7 months ago #123027 by StefanBasen
Matrix ( Numbers) with a usual Matrix? was created by StefanBasen
Hello everyone!

Im looking for a Solution to my Matrix Problem. Thing is, the first 4 Questionparts are Numbers ( Dropdown or small free text) but at the Last Questionpart ( Questionpart 5 ) on the X-Scale needs a Checkbox for "Cant answer this Question". But how can i get that one to work?

Thank you
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 7 months ago #123032 by tpartner
Replied by tpartner on topic Matrix ( Numbers) with a usual Matrix?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: StefanBasen
The topic has been locked.
  • StefanBasen
  • StefanBasen's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
8 years 7 months ago #123033 by StefanBasen
Replied by StefanBasen on topic Matrix ( Numbers) with a usual Matrix?
Sorry for the maybe stupid Question but well..where to insert this Code?"Source of the array" dont say anything to me :(
The topic has been locked.
  • tammo
  • tammo's Avatar
  • Offline
  • Official LimeSurvey Partner
  • Official LimeSurvey Partner
More
8 years 7 months ago - 8 years 7 months ago #123034 by tammo
Replied by tammo on topic Matrix ( Numbers) with a usual Matrix?
TPartner probably meant to write: put the code in the source of the question. That is the textfield of the question after you push the button "Source" in the editor.



Tammo ter Hark at Respondage
For Limesurvey reporting, education and customized themes
respondage.nl
Attachments:
Last edit: 8 years 7 months ago by tammo.
The topic has been locked.
  • StefanBasen
  • StefanBasen's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
8 years 7 months ago - 8 years 7 months ago #123036 by StefanBasen
Replied by StefanBasen on topic Matrix ( Numbers) with a usual Matrix?
Did paste´n copy on this Code but all that happend is, that the whole code is visible in the Question Window. And where to put the usual Question?
What i did Step by Step:

1. opened the existing Question witch is set to Matrix ( Numbers )
2. clicked on "Source Code" deleted everything that was inside and paste that Code
3. clicked again on "Source Code" and insered my Question again.
4. clicked "Save"

when i now click on "preview of this Question" the Question Text has my Question in it followed by this:

1172') // Add some classes to the answer cells $('td.question-item', thisQuestion).addClass('normal-opt'); $('tr.subquestions-list', thisQuestion).each(function(i) { $('.normal-opt:last', this).removeClass('normal-opt').addClass('exlusive-opt') }); // Insert the checkboxes $('.exlusive-opt input[type="text"]', thisQuestion).hide(); $('.exlusive-opt', thisQuestion).append(''); // A listener on the text inputs $('.normal-opt input[type="text"]', thisQuestion).on('keyup change paste', function() { var thisInput = $(this); var thisRow = $(this).closest('tr.subquestions-list'); setTimeout(function() { if(thisInput.val() != ''){ $('.exlusive-opt input[type=checkbox]', thisRow).prop('checked', false); $('.exlusive-opt input[type=text]', thisRow).val(''); } }, 100); }); // A listener on the checkboxes $('.exlusive-opt input[type="checkbox"]', thisQuestion).change(function(event) { var thisCell = $(this).closest('td.question-item'); var thisRow = $(this).closest('tr.subquestions-list'); if($(this).is(':checked')) { $('input[type=text]', thisCell).val(1); $('.normal-opt input[type=text]', thisRow).val(''); } else { $('input[type=text]', thisCell).val(''); } }); // Initial states $('.exlusive-opt input[type="text"]', thisQuestion).each(function(i) { var thisCell = $(this).closest('td.question-item'); if($(this).val() != '') { $('input[type=checkbox]', thisCell).prop('checked', true); } }); });

so what went wrong?

i have to add: im using a German Version of LS and maybe my Version dont understands that {QID} Placeholder?
Version is: Version 2.06+ Build 150619
Last edit: 8 years 7 months ago by StefanBasen.
The topic has been locked.
  • tammo
  • tammo's Avatar
  • Offline
  • Official LimeSurvey Partner
  • Official LimeSurvey Partner
More
8 years 7 months ago - 8 years 7 months ago #123037 by tammo
Replied by tammo on topic Matrix ( Numbers) with a usual Matrix?
Please see:
manual.limesurvey.org/Global_settings#Security

The following setting: "Filter HTML for XSS" should be off.


Tammo ter Hark at Respondage
For Limesurvey reporting, education and customized themes
respondage.nl
Last edit: 8 years 7 months ago by tammo.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 7 months ago #123038 by tpartner
Replied by tpartner on topic Matrix ( Numbers) with a usual Matrix?
Also, please refer to this in the manual - manual.limesurvey.org/Workarounds:_Manip....29_in_LimeSurvey.3F

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • StefanBasen
  • StefanBasen's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
8 years 7 months ago #123039 by StefanBasen
Replied by StefanBasen on topic Matrix ( Numbers) with a usual Matrix?
Thank you tpartner & tammo! With the Filter set to off the Code worked. One last Question : is this also compatible with Dropdown?
The topic has been locked.
  • StefanBasen
  • StefanBasen's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
8 years 7 months ago #123083 by StefanBasen
Replied by StefanBasen on topic Matrix ( Numbers) with a usual Matrix?
Huh tried to use it with Dropdown Menu´s..looks like im too stupid for that :D
Has someone the Code that works with Dropdown instead of free Text?
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 7 months ago #123140 by tpartner
Replied by tpartner on topic Matrix ( Numbers) with a usual Matrix?
This should do the trick with drop-downs. It will hide the drop-downs in the last column and insert check-boxes. Checking a box will set all other cells in that row to null and record 99999 for the last cell.

Code:
<script type="text/javascript" charset="utf-8">    
  $(document).ready(function() {
 
    // Identify this question
    var thisQuestion = $('#question{QID}');
 
    // The value recorded in data if last-column checkbox is checked
    var noAnswer = 99999;
 
    // Add some classes to the answer cells
    $('td.question-item', thisQuestion).addClass('normal-opt');
    $('td.question-item:last-child', thisQuestion).removeClass('normal-opt').addClass('exlusive-opt')
 
    // Insert the checkboxes
    $('.exlusive-opt select', thisQuestion).hide();
    $('.exlusive-opt', thisQuestion).append('<input type="checkbox" class="checkbox">');
 
    // Insert a new option in the last column selects
    $('.exlusive-opt select', thisQuestion).append('<option value="'+noAnswer+'">'+noAnswer+'</option>');
 
    // A listener on selects
    $('.normal-opt select', thisQuestion).on('change', function() {
      var thisRow = $(this).closest('tr.subquestions-list');
      if($(this).val() != ''){
        $('.exlusive-opt input[type=checkbox]', thisRow).prop('checked', false);
        $('.exlusive-opt select', thisRow).val('');
        $('.exlusive-opt input[type="hidden"]', thisRow).attr('value', '');
      }
    });  
 
    // A listener on the checkboxes
    $('.exlusive-opt input[type="checkbox"]', thisQuestion).on('change', function(event) {
      var thisCell = $(this).closest('td.question-item');
      var thisRow = $(this).closest('tr.subquestions-list');
      if($(this).is(':checked')) {
        $('select', thisCell).val(noAnswer);
        $('input[type="hidden"]', thisCell).attr('value', noAnswer);
        $('.normal-opt select', thisRow).val('');
        $('.normal-opt input[type="hidden"]', thisRow).attr('value', '');
      }
      else {
        $('.exlusive-opt select', thisRow).val('');
        $('.exlusive-opt input[type="hidden"]', thisRow).attr('value', '');
      }
    });
 
    // Initial states
    $('.exlusive-opt input[type="hidden"]', thisQuestion).each(function(i) {
      var thisCell = $(this).closest('td.question-item');
      if($(this).attr('value') == noAnswer) {
        $('input[type=checkbox]', thisCell).prop('checked', true);
        $('select', thisCell).val(noAnswer);        
      }
    });
  });
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • StefanBasen
  • StefanBasen's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
8 years 1 month ago #130577 by StefanBasen
Replied by StefanBasen on topic Matrix ( Numbers) with a usual Matrix?
is it possible to change this code that the Answers wont get deleted in the dropdowns and that overall only 3 of those checkboxes can be checked?
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose