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 6 months ago - 1 year 6 months ago #232054 by qiangqi
Please help us help you and fill where relevant:
Your LimeSurvey version: [see right hand bottom of your LimeSurvey admin screen]
Own server or LimeSurvey hosting:
Survey theme/template:
==================
Hello everyone,

I have met a problem when i try to create a table. as you know, the apple-banana example writen by tony is famous in the forum and I paste the command in my javascript and it works well. but I don't want to keep the apple and banana constantly. if in previous question of "which fruit do you dislike" and the answer is apple, then in the table, the option column of apple would not appear. I guess I could use a "if statement" to achieve it, but it doesn't work. so does anyone now how to solve the problem.

Best,
Qiang
Last edit: 1 year 6 months ago by qiangqi.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 6 months ago #232055 by Joffm
Hi,
yes, you show or hide the HTML column by an IF-statement.

But your IF-statement is not correct.
You say somethinbg like
if (fuit=='apple') {<td...}
But the IF is an implemented function.
So this has to be inside the curly brackets, like
{if(fruit=='apple',"wWat happens if TRUE","What happens if FALSE")}

See the examples in the manual. like
[url] manual.limesurvey.org/ExpressionScript_H...7BMrs.7D_Smith....22 [/url]

And I advice: Instead of these "<span style" orgias create some classes for your rows.

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 6 months ago #232059 by qiangqi
Hi Joffm,

Thanks for your reply. I have seen so many replies you gave and I am happy I could get your reply for my question. Actually, I already try the format you told me, but the "if" doesn't still highlight, you could see it in the attachment. so I think the if function couldn't be identified in the command. for your advice of creating class for rows, I copy your another reply using this, and I think it is clear. thanks for your reply.

Best,
Qiang
Attachments:

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 6 months ago #232061 by Joffm
Try it without linefeeds
Code:
        <tr>
            <td class="td1">Which ONE of the following are the BEST OPTIONS for you? </td>
            <td class="tdf"> </td>
{if(I0==1,'<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>

 

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
1 year 6 months ago #232064 by Joffm
And you can simplify it by only switching the class (either "tdn/tdf" or "hidden")
Like
Code:
        <tr>
            <td class="td1">Location</td>
            <td class="tdf"> </td>
            <td class="tdn">Option 1</td>
            <td class="tdf"> </td>
            <td class={if(I0==1,'hidden','tdn')}>Option 2</td>
            <td class={if(I0==1,'hidden','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={if(I0==1,'hidden','tdn')}>Option 2</td>
            <td class={if(I0==1,'hidden','tdf')}> </td>
            <td class="tdn">Option 3</td>
        </tr>



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 6 months ago #232071 by qiangqi
Hi Joffm,

Thanks for your reply. It doesn't still work, although I totally copy your command.
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>
{if(I0==1,'<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>
Attachments:

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 6 months ago #232073 by Joffm
What doesn't work?
Is there a question I0 (list(radio)) with codes 1 and 2?
How does the question overview look like? (screenshot)
How does the question look like if you enter 1 resp. 2 in question I0?

Instead of showing these small pictures which are not very sharp, you'd better attach a lss export of this part of your survey.

Then I will send you a working example.

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 6 months ago #232077 by qiangqi
Hi Joffm,

actually, I just want to know how to create a tale in terms of the previous answer. in my survey, a multiple choice of coding with ptransportmode and the choices include PT1-PT5,but when i set it as a condition in IF statement, it will disappear. you could find it in the lss file. and what I said about it doesn't work means the if command doesn't highlight. 

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 6 months ago #232079 by Joffm
HI,
oh, still this "never ending" survey of the TUE.
You shouldn't have started with the apple - banana example.
There exist better solutions (layout) of this by your (former) fellow students

Okay:
Which editor do you use.
You know there are three included in LimeSurvey.
And you should not use the "Inline HTML editor"; better the "no HTML editor".  You select in your personal settings.
 
The HTML editor has its own ideas how to handle, quotes.

Importing your survey I see this
Code:
        <tr>
            <td class="td1">riding time</td>
            <td class="tdf"> </td>
            <td class="tdn"><strong>Option 1</strong></td>
            <td class="tdf"> </td>
            <td class="{if(ptransportmode_PT1.NAOK">Option 2</td>
            <td class="{if(ptransportmode_PT1.NAOK"> </td>
            <td class="tdn">Option 3</td>
        </tr>

And if you compare with my previous post there is no quote here <td class="{if(
Only
<td class={if(ptransportmode_PT1=='Y','hidden','tdn')}>Option 2</td>

Later I will send this back, only the relevant parts

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
1 year 6 months ago #232084 by Joffm
Here is the example.
(With the javascript to insert the radios)
 

File Attachment:

File Name: limesurvey...5327.lss
File Size:38 KB


 



Or
 



Joffm

By the way:
Why did you enter the havascript to move the "Other" option? There is no "Other" option in the question.
Do you want to insert it?

And what is the meaning of this array?
 

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 6 months ago #232085 by qiangqi
Hi Joffm,

Thanks for your help. the "option" choice is just for giving respondent a choice and it would not be inset in the table. and this array you don't know meanings is not useful, because the last group is just a exercise for making a table and the command in the group is from the forum and I just want to know the result using these command.

thanks for your reply again. I will try to change the editor next. honestly, I really don't know there are three editors. 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 6 months ago #232086 by qiangqi
Hi Joffm,

actually, as you know, the limesurvey I use is a group account and I am just a user, so I can't change the HTML editor mode. it is so pity. thanks for your help again!

Best,
wishes

Please Log in to join the conversation.

Lime-years ahead

Online-surveys for every purse and purpose