Welcome to the LimeSurvey Community Forum

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

Is there an expression script function that can set visibility on or off

  • linuxhooligan
  • linuxhooligan's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
5 months 4 weeks ago - 5 months 4 weeks ago #264824 by linuxhooligan
Please help us help you and fill where relevant:
Your LimeSurvey version: Version 5.6.55+240220
Own server or LimeSurvey hosting: shared hosting
Survey theme/template: fruity
==================

Hi.

I am using the following if statement tests:

{if(VAR_item01>10,VAL01result,'')}
{if(VAR_item01>10,VAL02result,'')}
.. etc.

Basically, I am generating a report on a single page by testing for a list of traits and, if the score is greater than 27 display a value stored somewhere in the form, otherwise, display and empty string.  The problem that I am running into is that if I have 30 items that I am testing for, some of them are going to have a score of less than 10 and print out an empty string resulting in spaces in the list and it doesn't look presentable.

QUESTION: Is there an expression script function similar to this that can either print out 'text' or set the display value to 0 for the item being tested?

NOTE: I know that the CONDITION field can be used to hide a question and the answers on the page will be vertically aligned with no empty spaces and be very presentable.  I am wanting to code this up using expression script in a single question as it allows for less complexity, easier debugging and greater visual presentation flexibility. 

Any suggestions are most welcome.
Last edit: 5 months 4 weeks ago by linuxhooligan.

Please Log in to join the conversation.

  • linuxhooligan
  • linuxhooligan's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
5 months 4 weeks ago #264825 by linuxhooligan
Even this code:

{if(VAR_item01>10,VAL01result)}
{if(VAR_item01>10,VAL02result)}

Returns this value in the page:

<p><br></p>

<p><br></p>

Is there a way to not return a <p><br></p> somehow?

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 months 4 weeks ago #264826 by Joffm
This is because you always enter the linefeed (each expression in a separate line)
I'd join it with a linefeed only in positive results.
{join(if(Q1_1>10,"Text 1<br />",""),if(Q1_2>10,"Text 2<br />",""),if(Q1_3>10,"Text 3<br />",""),if(Q1_4>10,"Text 4<br />",""),if(Q1_5>10,"Text 5<br />",""))}



There may be are some other options, just think it over and have a look at the implemented functions.

Joffm

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

Please Log in to join the conversation.

  • linuxhooligan
  • linuxhooligan's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
5 months 4 weeks ago #264827 by linuxhooligan
THIS WORKS!

Apologies for my enthusiasm. Two things:

This is a real answer from a real programmer. I really appreciate it. My respect for Limesurvey keeps on growing, expression script is quickly becoming a favourite feature.

Joffm, thank you very kindly for your assistance with my other question about sorting, that was an incredibly powerful example of what Limesurvey can do. I will get back to you on that, I want to add a bit to the sample so we can add that to the example surveys in the documentation, it is super useful.

For any noobs here, the example in this question is superb. It is a simple example of how understanding expression script expands what is possible.

As always, thank you very kindly Joffm and the entire community.

Please Log in to join the conversation.

Moderators: holchtpartner

Lime-years ahead

Online-surveys for every purse and purpose