Welcome to the LimeSurvey Community Forum

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

Dynamically create expression using javascript.

  • czysty
  • czysty's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 1 month ago - 4 years 1 month ago #194341 by czysty
Hi,

I would like to get the question Id using javascript and concatenation.
Let’s suppose I have a question that has a code: Ph1.
The expression written by hand {Ph1.qid} works very well.
But I need to iterate through a certain number of questions that have names:

Ph1,Ph2,Ph3 respectively.

So in js I try:

var number = 1;
var baseCode = 'Ph';
var qid = '\{' + baseCode + number.toString() + '.qid\}';
console.log(qid);

This returns the literal string ‘{Ph1.qid}’ instead of an actual qid code.
How can I do this?

Thanks.
Last edit: 4 years 1 month ago by czysty.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 1 month ago #194343 by tpartner
You cannot use JavaScript to define Expression Manager variable names. EM is rendered at the server level but JavaScript is not rendered until after the page is loaded so it cannot modify the EM variable name.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • czysty
  • czysty's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 1 month ago - 4 years 1 month ago #194352 by czysty
Thanks tpartner. I was trying to give the possibility to show only questions the user chooses to answer.
Could you advice me some workaround for this problem?

The situation:

Choose a question:
a - Ph
b - In
c - Ac

if answer == Ph :
(#question{Ph1.qid}.show #question{Ph2.qid}.show #question{Ph3.qid}.show)

These 3 questions are: Array and two huge free text.
Last edit: 4 years 1 month ago by czysty.
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 1 month ago #194354 by DenisChenu
Replied by DenisChenu on topic Dynamically create expression using javascript.
? Relevance is set for this ....

And here : condition editor work ...

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.

Lime-years ahead

Online-surveys for every purse and purpose