Welcome to the LimeSurvey Community Forum

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

creating a table using javascript and the options are based previous answer

  • qiangqi
  • qiangqi's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
1 year 7 months ago #232088 by qiangqi
Hi Joffm,

I try to copy your example you wrote to my survey, but it shows it can't because of the version. by the way, the version of my limesurvey is Limesurvey cloud version 3.28.24

thanks for your attention.

Best,
Qiang

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 7 months ago #232090 by Joffm
Hi,
of course my lss export is a version 3.x. export.
So you should be able to import it.

What do you mean by "copy"?
How does the error message look like? (screenshot)

Joffm

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

Please Log in to join the conversation.

  • qiangqi
  • qiangqi's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
1 year 7 months ago #232097 by qiangqi
Hi Joffm,

this is the screenshot.
now that I could not change the HTML modes, I want to know if I could use if-statement in inline HTML editor.

best,
Qiang
Attachments:

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 7 months ago #232100 by Joffm
This is what I sent

So you should be able to import.

But nevertheless, here again.
 

File Attachment:

File Name: limesurvey... (2).lss
File Size:38 KB


In about an hour I show you again the script.


 

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

Please Log in to join the conversation.

More
1 year 7 months ago #232102 by jelo
Your first file was fine. I was able to import it in demo.limesurvey.org (LS5).

Perhaps the file download was incomplete or the cloud version has a bug (it's not 100% identically to the community version.

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users

Please Log in to join the conversation.

  • qiangqi
  • qiangqi's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
1 year 7 months ago #232105 by qiangqi
Hi Joffm,

I have known the reason. because the limesurvey of mine is a group account, so I have to create a new account for open the file you sent to me, and the new account is version 5.xx. Now, I just use other version 3 to try it and it could be imported. but it still has problem and now I am not sure it is why. I am trying to solve it.
from the first picture, this is the command from you and it shows undefined variable ,so I change it to my vatiable from ptm_1 to ptransportmode_PT1, but the errors appear more, shown as second picture. and the last picture is the command after I changed the variable name.

Best,
Qiang

Please Log in to join the conversation.

  • qiangqi
  • qiangqi's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
1 year 7 months ago #232106 by qiangqi
Hi jelo,

thanks for your reply. you are right, the cause is version. and then I think the HTML editor also play a important role.

Best,
Qiang

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 7 months ago #232107 by Joffm
And I imported right now into the cloud

But usually the TUE Installation works fine.
There were a lot of questions of several students in the past.

Well, here the script:
First:
I renamed
the question "ptransportmode" to "ptm"
the subquestions "PT1".. "PT5" to 1,2,3,4,5

In this script only items that were selected in ptm are displayed in the array.
If this is not the correct understanding and only the "not selected" are displayed,
either switch "hidden","tdn/f"
or change the condition from "==" to "!="

There are nested quotes only in the section "Move the radios". Keep an eye on them.
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={if(ptm_1=="Y","tdf","hidden")}> </td>
      <td class={if(ptm_1=="Y","tdn","hidden")}><strong>car</strong></td>
      <td class={if(ptm_3=="Y","tdf","hidden")}> </td>
      <td class={if(ptm_3=="Y","tdn","hidden")}><strong>bike</strong></td>
      <td class={if(ptm_2=="Y","tdf","hidden")}> </td>
      <td class={if(ptm_2=="Y","tdn","hidden")}><strong>ebike</strong></td>
    </tr>
  </thead>
  <tbody>
    <tr style="height: 3px; text-align: center;">
    </tr>
    <tr>
      <td class="td1">riding time</td>
      <td class={if(ptm_1=="Y","tdf","hidden")}> </td>
      <td class={if(ptm_1=="Y","tdn","hidden")}>Option 1</td>
      <td class={if(ptm_3=="Y","tdf","hidden")}> </td>
      <td class={if(ptm_3=="Y","tdn","hidden")}>Option 2</td>
      <td class={if(ptm_2=="Y","tdf","hidden")}> </td>
      <td class={if(ptm_2=="Y","tdn","hidden")}>Option 3</td>
    </tr>
    <tr style="height: 3px; text-align: center;">
    </tr>
    <tr>
      <td class="td1">cost</td>
      <td class={if(ptm_1=="Y","tdf","hidden")}> </td>
      <td class={if(ptm_1=="Y","tdn","hidden")}>Option 1</td>
      <td class={if(ptm_3=="Y","tdf","hidden")}> </td>
      <td class={if(ptm_3=="Y","tdn","hidden")}>Option 2</td>
      <td class={if(ptm_2=="Y","tdf","hidden")}> </td>
      <td class={if(ptm_2=="Y","tdn","hidden")}>Option 3</td>
    </tr>
    <tr style="height: 3px; text-align: center;">
    </tr>
    <tr>
      <td class="td1"><strong>Which option would you prefer?</strong></td>
      <td class={if(ptm_1=="Y","tdf","hidden")}> </td>
      <td class={if(ptm_1=="Y","tdn","hidden")}> </td>
      <td class={if(ptm_3=="Y","tdf","hidden")}> </td>
      <td class={if(ptm_3=="Y","tdn","hidden")}> </td>
      <td class={if(ptm_2=="Y","tdf","hidden")}> </td>
      <td class={if(ptm_2=="Y","tdn","hidden")}> </td>
    </tr>
  </tbody>
</table>
 
<script type="text/javascript" charset="utf-8">
  $(document).on('ready pjax:scriptcomplete',function(){
 
    // Identify this question
    var thisQuestion = $('#question{QID}');
 
    // Move the radios
    {if(ptm_1=="Y","$('.question-text table:eq(0) tr:last td:eq(2)', thisQuestion).append($('.subquestion-list .answers-list:eq(0) .answer-item:eq(0) *', thisQuestion));","")}
    {if(ptm_3=="Y","$('.question-text table:eq(0) tr:last td:eq(4)', thisQuestion).append($('.subquestion-list .answers-list:eq(0) .answer-item:eq(1) *', thisQuestion));","")}
    {if(ptm_2=="Y","$('.question-text table:eq(0) tr:last td:eq(6)', thisQuestion).append($('.subquestion-list .answers-list:eq(0) .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>
<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;
  }
  tbody td.tdn {
   background-color:#f2f2f2;
   text-align:center;
   font-size:11pt;
   vertical-align:middle;
  }
 
  tbody td.tdf {
    width: 0px;
  }
</style>

Here the script as *.txt file
 

File Attachment:

File Name: TUE_script.txt
File Size:4 KB


Joffm

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

Please Log in to join the conversation.

  • qiangqi
  • qiangqi's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
1 year 7 months ago #232116 by qiangqi
Hi Joffm,

Thanks for your patience. Because the problem of my version of limesurvey, the code of "<td class={if(ptm_1=="Y","tdf","hidden")}> </td>" would change to "<td class={if(ptm_1==&quot;Y&quot;,&quot;tdf&quot;,&quot;hidden&quot;)}"> </td>". I am so ashamed for wasting you so much time on my problem. thank you again. I will try my best to solve this question. you really give me big help. thank you very much.

Best,
Qiang

Please Log in to join the conversation.

  • qiangqi
  • qiangqi's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
1 year 7 months ago #232123 by qiangqi
Hi Hoffm,

it works!!! the command I use is shown as first figure, but from question summary, you could not see the if-statement. this condition is weird. but anyway, it works, when i choose car or bike, the alternative in the table could change in terms of my choice.

Thanks for your help. It is hard for me to describe my grateful for you. Thanks again!!!

Best,
Qiang

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 7 months ago #232155 by Joffm
Now spomething quite different.
I already asked why you did not use the work of your (former) fellow student (user name here: Xueting)?
I already proposed a quite better display of the trips like
 
And instead of the time picker use a input mask. More convenient for respondents.

Especially because of your 0-5 subtrips this dynamic display of lines seems to be the best way to display it.

So you can save a lot of space and make it more pleasant for the respondent.

You shouldn't use an array(5-point) if you have to explain the scale.
 
Use an array
 


And still there is no option (j1purpose) to go to a train station for national travalling.
only To get to airport or train station for international traveling 
A bit strange.

Joffm

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

Please Log in to join the conversation.

  • qiangqi
  • qiangqi's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
1 year 7 months ago #232182 by qiangqi
Hi Joffm,

Actually, my questionnaire starts from "personnel or household information". the part before that is just a reference and no sense in my survey. The table I want to design is shown as the picture in attachment. the alternatives of transport modes could change in terms of the previous answers. I hope to inset some small icon in the table and keep aligning for the green part and blue part. Do you think if it is possible for the table design in limesurvey.

Best,
Qiang
Attachments:

Please Log in to join the conversation.

Lime-years ahead

Online-surveys for every purse and purpose