Welcome to the LimeSurvey Community Forum

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

How to add a condition to each sub-question of a double-scale table

  • marief99
  • marief99's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 5 months ago #190196 by marief99
Hello,
I do not know how to create a table that would allow participants to click on the button "Was the opportunity available to you?" and on "Did you participate?", then add a condition that would allow people to indicate how many hours of training they received when they say they participated in the training. See image and example for more information. Thank you very much!
Marie-France
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 5 months ago - 4 years 5 months ago #190201 by Joffm
Hi, Marie-France,
this is a nice paper-pencil questionnaire, but - as often -, you can draw a lot, but it is difficult to realize as an web based survey.
Well, in my opinion there are two solutions available at the moment here in the forum.

The first is based on the idea that it is not necessary to check "opportunity" and "participation" independently.
If somebody participated he had the opportunity. So we can check these two options as radio buttons.


The second let's you select both (just to show it)


Then you have to validate that "hours" is only entered if participated,
and in the second case that "participation" is only entered if "opportunity".

If you think this could suit your wishes, I'll send an LSS file of this (has to be improved a bit).

Joffm

One addition:
Improvement of first example:

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 4 years 5 months ago by Joffm.
The following user(s) said Thank You: marief99
The topic has been locked.
  • marief99
  • marief99's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 5 months ago #190207 by marief99
Wow! Thank you!

I think that the best solution for my survey is to use the second option (with the yes/or question) although I like the option with the buttons which is faster to respond.

So from what I understand, you will send me a code so that I can use the 2nd option you created?

Thanks again Joffm!!
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 5 months ago #190209 by Joffm
Here you are

File Attachment:

File Name: limesurvey...1891.lss
File Size:20 KB


The main thing is the javascript.
I called the X-axis codes "X001", "X002", ... Here you may adapt the wording.
Code:
<script type="text/javascript" charset="utf-8">
 
  $(document).on('ready pjax:scriptcomplete',function(){
    var thisQuestion = $('#question{QID}');
 
    // Insert selects
    $('.answer-item.answer_cell_X001', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\
                          <option value="">Yes/No...</option>\
                          <option value="1">Yes</option>\
                          <option value="2">No</option>\
                        </select>'); 
    $('.answer-item.answer_cell_X002', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\
                          <option value="">Yes/No...</option>\
                          <option value="1">Yes</option>\
                          <option value="2">No</option>\
                        </select>'); 
 
    // Listeners
    $('.inserted-select', thisQuestion).on('change', function(i) {
      if($(this).val() != '') {
        $(this).closest('.answer-item').find('input:text').val($.trim($('option:selected', this).text())).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());
      var selectval = $('select.inserted-select option', thisCell).filter(function () { return $(this).html() == inputText; }).val();
      $('select.inserted-select', thisCell).val(selectval);
    });
 
    // Clean-up styles
    $('select.inserted-select', thisQuestion).css({
      'max-width': '100%'
    });
    $('.with-select input:text', thisQuestion).css({
      'position': 'absolute',
      'left': '-9999em'
    });
  });
</script>

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • marief99
  • marief99's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 5 months ago #190214 by marief99
OK...and know, don't laugh at me but I don't know how to integrate your LSS file in my questionnaire. I tried to "import a question", but the software requires a format * lsq

If you can help me when you'll have time, I would really appreciate.

Marie-france
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 5 months ago #190223 by DenisChenu

marief99 wrote: If you can help me when you'll have time, I would really appreciate.

Seriously ? :dry:

You can copy/paste yhe @Joffm method, if you need a professional service : contact a professional : www.limesurvey.com/support

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 5 months ago #190263 by holch
LSS == LimeSurvey Survey file
LSG == Limesurvey Group file
LSQ == Limesurvey Question file

So yes, you can not import a whole survey file into your survey.

The LSS file is for you to have a look at it how it works and then implement it into your own survey. You could even export the question groups (as LSG) or questions (LSQ) that you need and then import them into your survey.

However, it make sense that you look at how Joffm did it and then implement it into your own survey. Depending on your survey structure you might have to adapt the script provided by Joffm.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The following user(s) said Thank You: marief99
The topic has been locked.
  • marief99
  • marief99's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 5 months ago #190275 by marief99
Thank you Holch for this empathic and cordial response. I really appreciate...
Marie-France
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 5 months ago #190300 by Joffm
Unfortunately I was on our market research fair for two days.
One addition to holch's explanation.

Why do we prefer to attach LSS files?
LSS files you can import as a new survey without any preparation.
LSQ and LSG files you can import into an existing survey.
But now the crucial point.
LSQ and LSG are language dependent.
So, if I send a file created with base language "English" you can't import it into a survey that doesn't contain this language.

So in my opinion LSQ and LSG exports should only be used internally to copy them from one survey to a second, or to build a library of often used questions.

But here it is very frustrating if we get an LSQ export with an unknown base language.

All the best
Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • marief99
  • marief99's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 5 months ago #190613 by marief99
Hi everybody (and Joffm especially!)

A friend helped me integrate the question as programmed by Joffm.

However, I wonder how to allow numeric responses only in the 3rd column of the table.

Also, how do you add a condition for the 3rd column to appear if and only if respondents answer "yes" to the 2nd question? (did you participate in the activity?)

Thank you in advance for your valuable advice!

Marie-France
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 5 months ago #190614 by Joffm
Hi, Marie France,
the easy method is to validate
1. that there are only entries in third column if column 2 was answered "Yes":
Something like "Q1_Y001_X002!='Yes' and is_empty(Q1_Y001_X003)" ...
2. that there are only numeric entries in column 3 (here you may use the function "is_numeric") like "is_numeric(Q1_Y001_X003)"
manual.limesurvey.org/Expression_Manager...mplemented_functions

There might be a way to clear and set the third column to "readonly" until column 2 is "Yes", but that's beyond my capabilities.
I am not very familiar with javascript; and the provided script is not mine, but here from the forum and a little bit adapted by me..

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: marief99
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose