Welcome to the LimeSurvey Community Forum

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

Add Checkbox above Array (Text)?

  • psychgit
  • psychgit's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 years 6 months ago #230701 by psychgit
Add Checkbox above Array (Text)? was created by psychgit
Please help us help you and fill where relevant:
Your LimeSurvey version: [Version 3.24.2]
Own server or LimeSurvey hosting: Lime Survey Hosting
Survey theme/template: Array (Text)
==================
Hello,

I am trying to add a single checkbox so that it appears below my questions and above my Array (Text). I have no experience with Javascript so any help would be much appreciated! Here is my source question script: <p><span style="font-size:20px;">Dimension 3. Social Impact of Endometriosis </span></p>

<p><span style="font-size:20px;">Please describes how much endometriosis has affected your life by providing one of the following responses for the four time periods: </span></p>

<ul>
    <li><span style="font-size:20px;">Not at all </span></li>
    <li><span style="font-size:20px;">A little </span></li>
    <li><span style="font-size:20px;">Somewhat </span></li>
    <li><span style="font-size:20px;">Quite a lot </span></li>
    <li><span style="font-size:20px;">Very much </span></li>
    <li><span style="font-size:20px;">Not applicable </span></li>
</ul>

<p><span style="font-size:20px;">Please note that you may refuse to answer any questions on the questionnaire by leaving the box blank.</span> <script type="text/javascript" charset="utf-8">
  $(document).on('ready pjax:scriptcomplete',function(){
    var thisQuestion = $('#question{QID}');
 
    // Insert selects
    $('.answer-item', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\
      <option value="">Please choose...</option>\
      <option value="1">Not at all</option>\
      <option value="2">A little </option>\
      <option value="3">Somewhat </option>\
      <option value="4">Quite a lot </option>\
      <option value="5">Very much </option>\
      <option value="6">Not applicable </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></p>

<p> </p>

<p> </p>

<p><strong><span style="font-size:20px;"><span style="font-family:Arial,Helvetica,sans-serif;">Because of My Endometriosis:</span></span></strong></p>
 

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 6 months ago - 2 years 6 months ago #230707 by Joffm
Replied by Joffm on topic Add Checkbox above Array (Text)?
Hi,
Don't show only the source code of your question text.
The rest of the question settings are missing.

Show a screenshot, attach a lss export of this relevant question,

What is the meaning of this checkbox?
Something like "not applicable"?
Can't you split the question and only display columns that are applicable? With a previous question to check this?

Be a bit more detailled.
Without this we can't advise different solutions

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 2 years 6 months ago by Joffm.

Please Log in to join the conversation.

  • psychgit
  • psychgit's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 years 6 months ago #230711 by psychgit
Replied by psychgit on topic Add Checkbox above Array (Text)?
Noted! I've attached the lsq export, and a screenshot of what I am trying to do (i.e, add checkbox). I am trying to add a box that respondents can tick off if all the questions aren't applicable.

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 6 months ago #230714 by tpartner
Replied by tpartner on topic Add Checkbox above Array (Text)?
Why bother with JavaScript. Simply insert a multiple-choice question with a single sub-question before the array question. Then display the array with relevance based on that sub-question being un-checked.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 6 months ago #230721 by Joffm
Replied by Joffm on topic Add Checkbox above Array (Text)?
Hi,
what did you send?
That is not a lss export, but a lsq.
So we have to create a survey, guessing the base language of your export (lsq and lsg exports are language sensitive)
and we have to create a group to be able to import your lsq.

Furthermore the survey wide settings are missing.

Please, ease the live of us volunteers.

And your lsq? There is nothing, really nothing in it.
Only this


But @tpartner told you, I told you before: Split the question.

Joffm
 

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

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 6 months ago #230733 by Joffm
Replied by Joffm on topic Add Checkbox above Array (Text)?
Hi, to explain a bit.
One question of type "multiple" with only one subquestion "not relevant"  (Q1).
Here you display the question text.

Followed by the array. (Q2)
The array is hidden, if the checkbox "not relevant" is selected -> relevance equation "Q1_SQ001!="Y"

Now a bit more styling by some css and javascript.
Merge the two questions with the classes "no-botton" in Q1 and "no question" in Q2.
Code:
.no-question { border-top:0; }
.no-question .question-title-container { display:none; }
.no-question .question-valid-container { display:none; }
.no-bottom { border-bottom:0;margin-bottom:0; }
.no-question .answer-container {
    padding-top: 0em;
    padding-bottom: 0.5em;
}
.no-bottom .answer-container {
    padding-bottom: 0em;
}

And to insert the "Endiometriosis" text into the array this javascript
Code:
<script type="text/javascript" charset="utf-8">    
    $(document).on('ready pjax:scriptcomplete',function(){
 
        // Identify this question
        var thisQuestion = $('#question{QID}');
 
        // Insert header text
        var insertedText = "Because of My Endometriosis:";
        $('table.subquestion-list thead tr:last td:first', thisQuestion).addClass('inserted-header').append(insertedText);
    });
</script>

Again with some css
Code:
<style type="text/css">td.inserted-header {
    font-size:20px;
    font-family:Arial,Helvetica,sans-serif;    
    font-weight: bold;
    text-align: left;
    vertical-align: middle !important;
}
</style>

Of course you may adapt to your needs.

Looks like this




Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: qiangqi

Please Log in to join the conversation.

Moderators: holchtpartner

Lime-years ahead

Online-surveys for every purse and purpose