Welcome to the LimeSurvey Community Forum

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

Multiple choice table and insert a list (dropdown) in table as answer options

  • LisaTW
  • LisaTW's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
3 years 1 week ago #215005 by LisaTW
Hi there,I’m trying to design a choice experiment in limesurvey. It’s my first time to use this software and I don’t know much about javascript.1, I’d like to fulfill this table in the system. Can I create something like this directly in Limesurvey?SpecificationsScenario  1Scenario 2Scenario 3LocationOption 1Option 2Option 3House typeOption 1Option 2Option 3Subquestion 3Option 1Option 2Option 3Subquestion 4Option 1Option 2Option 3Subquestion 5Option 1Option 2Option 3Subquestion 6Option 1Option 2Option 3Subquestion 7Option 1Option 2Option 3Subquestion 8Option 1Option 2Option 3Which house would you prefer to live?□□□Which house would you think is most suitable for old people?□□□ 2, And could this be possible to add list (drop down) in table as answer options? please see the attached picture. If anyone could provide some help or guidance that would be greatly appreciated. Thank you in advance for any assistance provided!!Lisa
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 1 week ago - 3 years 1 week ago #215011 by Joffm
[url] forums.limesurvey.org/forum/can-i-do-thi...a-array-texts#189538 [/url]

Here the general javascript (You have to adapt to your needs)
Code:
<script type="text/javascript" charset="utf-8">
  $(document).on('ready pjax:scriptcomplete',function(){
    var thisQuestion = $('#question{QID}');
    // Add a question class
    thisQuestion.addClass('custom-array');
 
    // Column-specific classes
    $('table.subquestion-list tr', thisQuestion).each(function(i) {
      $('th, td', this).each(function(i) {
        $(this).addClass('column-'+i);
      });
    });
 
 
    // Insert selects
    $('.answer-item.answer_cell_X001', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\
  <option value="">...</option>\
  <option value="1">Option 1</option>\
  <option value="2">Option 2</option>\
  <option value="3">Option 3</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>

[url] manual.limesurvey.org/Workarounds:_Manip...tc..29_in_LimeSurvey [/url]

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 3 years 1 week ago by Joffm.
The topic has been locked.
  • LisaTW
  • LisaTW's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
3 years 1 week ago #215020 by LisaTW
Thank you for the quick replay! You are really a hero for me.I’m also trying to design a choice experiment in limesurvey. There is a missing table in my first question. Can I create something like this directly in Limesurvey? (please see the attached picture)
there are two questions in the table. And I will design 27 tables, participant will see 9 out of 27 randomly.

Could you please tell me how to get table html? I'm using a software to transfer my table to html, but this didn't work well in Limesurvey

 
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 1 week ago #215021 by Joffm
Hi, Lisa,
at first: Could you please try to structure your text a bit better by using line feeds or paragraphs.
I know that this editor sometimes/often/always removes linefeeds when you paste a copied text.
But then add the linefeeds again, please.

Well, your question.
Because of the not existing structure I obviously misunderstood your first post.

This is something different  
Though there are a lot of post about this 
[url] forums.limesurvey.org/forum/can-i-do-thi...oint-analysis#203609 [/url]

Well, LimeSurvey does not support something like Conjoint.
As there are only 27 different tables, the best way is to create them all with fixed text.
Then you use the usual way to display randomly  of them.

Here a first screenshot from another post.
 

Later I will provide a sample survey

Joffm


 

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • LisaTW
  • LisaTW's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
3 years 1 week ago #215022 by LisaTW
Hi Joffm,

Thank you for your quick reply!

Sorry for the confusing structure, I did use linefeeds in editors but the result also make me confused.

Your first reply is about how to insert dropdown in table as answer option, the second reply is about multiple choice question. Thank you for your help!

About how to design a multiple choice question as in  forums.limesurvey.org/forum/can-i-do-thi...ions-in-a-box#184037

First paste the HTML table to display the question, and then the javascript part. I transfer excel table to HTML, but the table HTML didn't work in limesurvey survey. Could you please tell me how to get table HTML correctly. It's my first time to use limesurvey and javascript, everything is new for me. Thank you for your patience!

Lisa
 
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 1 week ago #215023 by Joffm
Hi,
well, in the link you used there is this first rough example 
 
which is not really suitable
You see there are three independent tables and you have problems to adjust row heights.

Then there is the "apple - banana" example.
 
In the thread there is the table structure as well.
This is the one I showed this morning.

The only difference is that you would like to have two subquestions. Therefore the javascript has to be adapted.

And this

I transfer excel table to HTML, but the table HTML didn't work in limesurvey survey

So you shouls show us your tries by sending a lss export of your survey.
.
As you might have seen in the table HTML it is a bit different.
There are small cölums between the "main" columns to give an impression of separation.
The one who first showed this did it like this.
And therefore we stay to it; otherwiese again changes in the javascript.

More to come

Joffm


 

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 1 week ago #215025 by Joffm
Hi, Lisa,
here a sample survey with 3 out of 8 question (up to you to adapt it to 9 out of 27)
 

 

File Attachment:

File Name: limesurvey...5958.lss
File Size:82 KB


I "cleaned" the structure of the HTML table a bit by using classes

You see it is a quite simple table and you see where you have to insert your  text.
Code:
<table style="border:0;padding:0;border-collapse:collapse;color:#000;width:100%">
  <thead>
    <tr>
      <td class="td1">Which of the following are the BEST OPTIONS for you? </td>
      <td class="tdf"> </td>
      <td class="tdn"><strong>Scenario 1</strong></td>
      <td class="tdf"> </td>
      <td class="tdn"><strong>Scenario 2</strong></td>
      <td class="tdf"> </td>
      <td class="tdn"><strong>Scenario 3</strong></td>
    </tr>
  </thead>
  <tbody>
    <tr style="height: 6px; text-align: center;">
    </tr>
    <tr>
      <td class="td1">Location</td>
      <td class="tdf"> </td>
      <td class="tdn">Option 1</td>
      <td class="tdf"> </td>
      <td class="tdn">Option 2</td>
      <td class="tdf"> </td>
      <td class="tdn">Option 3</td>
    </tr>
    <tr style="height: 6px; text-align: center;">
    </tr>
    <tr>
      <td class="td1">House type</td>
      <td class="tdf"> </td>
      <td class="tdn">Option 1</td>
      <td class="tdf"> </td>
      <td class="tdn">Option 2</td>
      <td class="tdf"> </td>
      <td class="tdn">Option 3</td>
    </tr>
    <tr style="height: 6px; text-align: center;">
    </tr>
    <tr>
      <td class="td1">Subquestion 3</td>
      <td class="tdf"> </td>
      <td class="tdn">Option 1</td>
      <td class="tdf"> </td>
      <td class="tdn">Option 2</td>
      <td class="tdf"> </td>
      <td class="tdn">Option 3</td>
    </tr>
    <tr style="height: 6px; text-align: center;">
    </tr>
    <tr>
      <td class="td1">Subquestion 4</td>
      <td class="tdf"> </td>
      <td class="tdn">Option 1</td>
      <td class="tdf"> </td>
      <td class="tdn">Option 2</td>
      <td class="tdf"> </td>
      <td class="tdn">Option 3</td>
    </tr>
    <tr style="height: 6px; text-align: center;">
    </tr>
    <tr>
      <td class="td1">Subquestion 5</td>
      <td class="tdf"> </td>
      <td class="tdn">Option 1</td>
      <td class="tdf"> </td>
      <td class="tdn">Option 2</td>
      <td class="tdf"> </td>
      <td class="tdn">Option 3</td>
    </tr>
    <tr style="height: 6px; text-align: center;">
    </tr>
    <tr>
      <td class="td1">Subquestion 6</td>
      <td class="tdf"> </td>
      <td class="tdn">Option 1</td>
      <td class="tdf"> </td>
      <td class="tdn">Option 2</td>
      <td class="tdf"> </td>
      <td class="tdn">Option 3</td>
    </tr>
    <tr style="height: 6px; text-align: center;">
    </tr>
    <tr>
      <td class="td1"><strong>Which house would you prefer to live?</strong></td>
      <td class="tdf"> </td>
      <td class="tdn"> </td>
      <td class="tdf"> </td>
      <td class="tdn"> </td>
      <td class="tdf"> </td>
      <td class="tdn"> </td>
    </tr>
    <tr>
      <td class="td1"><strong>Which house do you think is most suitable for old people?</strong></td>
      <td class="tdf"> </td>
      <td class="tdn"> </td>
      <td class="tdf"> </td>
      <td class="tdn"> </td>
      <td class="tdf"> </td>
      <td class="tdn"> </td>
    </tr>
  </tbody>
</table>

I defined the following css classes
Code:
<style type="text/css">thead td.tdn {
   background-color:#D4D7E4;
   text-align:center;
   font-size:11pt;
   padding-top:1em;
   padding-bottom:1em;
   vertical-align:middle;
  }
  thead td.td1 {
   background-color:#D4D7E4;
   text-align:left;
   padding-top:1em;
   padding-bottom:1em;
   vertical-align:middle;
   width:46%;
  }
tbody td.td1 {
   background-color:#f2f2f2;
   text-align:left;
   font-size:11pt;
   vertical-align:middle;
  }
tbody td.tdn {
   background-color:#f2f2f2;
   text-align:center;
   font-size:11pt;
   vertical-align:middle;
  }
 
  .tdf {
    text-align: center;
    width:=0%;
  }
</style>

And this is the javascript that inserts the radio buttons into the table
Code:
<script type="text/javascript" charset="utf-8">
  $(document).on('ready pjax:scriptcomplete',function(){
 
    // Identify this question
    var thisQuestion = $('#question{QID}');
 
    // Move the radios
    $('.question-text table:eq(0) tr:nth-last-child(2) td:eq(2)', thisQuestion).append($('.subquestion-list .answers-list:eq(0) .answer-item:eq(0) *', thisQuestion));
    $('.question-text table:eq(0) tr:nth-last-child(2) td:eq(4)', thisQuestion).append($('.subquestion-list .answers-list:eq(0) .answer-item:eq(1) *', thisQuestion));
    $('.question-text table:eq(0) tr:nth-last-child(2) td:eq(6)', thisQuestion).append($('.subquestion-list .answers-list:eq(0) .answer-item:eq(2) *', thisQuestion));
 
    $('.question-text table:eq(0) tr:last td:eq(2)', thisQuestion).append($('.subquestion-list .answers-list:eq(1) .answer-item:eq(0) *', thisQuestion));
    $('.question-text table:eq(0) tr:last td:eq(4)', thisQuestion).append($('.subquestion-list .answers-list:eq(1) .answer-item:eq(1) *', thisQuestion));
    $('.question-text table:eq(0) tr:last td:eq(6)', thisQuestion).append($('.subquestion-list .answers-list:eq(1) .answer-item:eq(2) *', thisQuestion));
 
    // Some classes for presentation
    $('.question-text table:eq(0) input:radio', thisQuestion).closest('td').addClass('answer-item radio-item text-center radio');
    $('.question-text table:eq(0) .radio-item label', thisQuestion).show();
 
    // Click event on the table cells
    $('.question-text table:eq(0) .radio-item', thisQuestion).on('click', function(e) {
      $('input:radio', this).trigger('click');
    });
    $('.question-text table:eq(0) input:radio', thisQuestion).on('click', function(e) {
      e.stopPropagation();
    });
 
    // Clean-up styles
    $('.answer-container', thisQuestion).hide();
    $('.question-text table:eq(0) .label-text', thisQuestion).remove();
    $('.question-text table:eq(0) .radio-text', thisQuestion).css({
      'cursor': 'pointer'
    });
  });
</script>

Best regards
Joffm
 

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • LisaTW
  • LisaTW's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
3 years 1 week ago #215035 by LisaTW
Hi Joffm,

Thank you for your kindness, I have followed your suggestions, but some parts didn't work.

Could you please tell me how to attach LSS file that only can be seen by you?

Lisa
 
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 1 week ago - 3 years 1 week ago #215036 by Joffm
Hi,
send the lss export of only this question.
Copy your survey, remove all other - not relevant - questions and send this 

What happened when you imported my sample survey?

Joffm

And: You still didn't mention it: Which version of LimeSurvey are you using?

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 3 years 1 week ago by Joffm.
The topic has been locked.
  • LisaTW
  • LisaTW's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
3 years 1 week ago #215047 by LisaTW
Hi Joffm,
Thank you for your quick reply!
I'm using Version 3.25.20. the attachment is part of my survey. Here are my problems:
1, Q26 is about inserting dropdown in table, but mine didn't show dropdown options.

2, part 3 is about multiple choice experiment, and participant will see 9 questions out of 27 randomly. but mine didn't insert the radio buttons into the table and couldn't show 9 questions randomly.
And could it be possible that one page only shows one question?

3, part 1 is about conditional question. Q13 is based on the answer of Q11, Q17 is based on the answers of Q11 and Q15. What I' m using is Relevance equation, however this didn't work, I may used the wrong relevance equation.

In part0, Q00 is designed to go on or stop the survey, if choose "yes", the survey will go on; if choose "no", then jump to "end part" and end the survey. 

When I imported your sample survey, it worked well. However when I use javascript to design my survey in school limesurvey system, it didn't work.

PS: Hi Joffm, When uploading attachment, there was a button for me to choose to decide who can see my attachment. but now I couldn't find it on the page. It's better to let you see my original survey. My school version can't import lss file. Could this be possible to make attachment only visible to you?

Lisa
Attachments:
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 1 week ago - 3 years 1 week ago #215064 by Joffm

However when I use javascript to design my survey in school limesurvey system, it didn't work.

In the survey you sent there are neither subquestions nor answer options in the question.
Well, the are overwritten by the script, but they have to be present. Otherwise there are no fields created in the database
Like
 



And the dropdowns:
You saw this line
    $('.answer-item.answer_cell_X001', 
Meaning the cell is coded "X001"; you let the default code "SQ001"

Either you change the subquestion codes in your question or in the javascript.

You see, I prefer to code the y-axis with "Y001", "Y002",... and the x-axis "X001", "X002",...
Less confusing, if there is in the dataset Q1_Y001_X003, instead of Q1_SQ001_SQ003 (what was column, what was row?)
And if you want to use the "self" and "that" variables in Expression manager this is mandatory; otherwise EM cannot distinguish between rows and columns.

 


part 1: Relevance equations are not surrounded by quotes
"Q11==2" or "Q11==3"
Q11==2 or Q11==3

You only surround answeroptions by quotes if the are alphanumerical, like Q11=="A1" or Q11=="A3"

In part0, Q00 is designed to go on or stop the survey, if choose "yes", the survey will go on; if choose "no", then jump to "end part" and end the survey. 

You'd better use a quota to screen out these people
Otherwise you had to add a relevance equation like Q00=="A1" to all your groups.
And why don't you use the built in consent?

Joffm

Some universities don't allow javascript.
But I think to remember that TUE allows javascript to the students.
Some time ago, there was an interesting survey of one of your colleagues that used javascript 
So there shouldn't be any problem except some small mistakes on your side.

And at last:
If you want, you may send the lss as private message.
Though I usualyy do not care about them, this is an exception.

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 3 years 1 week ago by Joffm.
The topic has been locked.
  • LisaTW
  • LisaTW's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
3 years 1 week ago - 3 years 1 week ago #215083 by LisaTW
Hi Joffm,

Thank you for your patience! Most problems are well solved according to your suggestions. Big thanks to you!

In your sample survey with 3 out of 8 question , could you tell me how to make G2 hidden? I see group relevance is 0, but I don't know how to achieve this in my survey. (1st picture is in sample survey, 2nd picture is in my survey)

Q00 is designed to go on or stop the survey, if choose "yes", the survey will go on; if choose "no", then jump to "end part" and end the survey. You suggested to use a quota to screen out these people. Could you show me a sample?

Lisa
Last edit: 3 years 1 week ago by LisaTW.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose