- Posts: 9
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
javascript and variables in the QID
- rodriguezm1
- Topic Author
- Offline
- New Member
Less
More
10 years 11 months ago #94117
by rodriguezm1
javascript and variables in the QID was created by rodriguezm1
I have a series of questions. They are strings. Call them Question1, Question2, Question3, etc.
I want to write script to generate the QID and display stuff. Example:
I also tried
Both of these codes to not display anything. But this code DOES display something
Can someone help me to know what is going on with this? Is this possible to do? Or do you always have to input the QID literally, and not use text manipulation with variables? Thanks
I want to write script to generate the QID and display stuff. Example:
Code:
<script type="text/javascript" charset="utf-8"> var i = 1; var theQID = "{Question" + i + ".answer}"; document.write(theQID); </script>
I also tried
Code:
<script type="text/javascript" charset="utf-8"> var i = 1; var theQID = "{that.Question" + i + ".answer}"; document.write(theQID); </script>
Both of these codes to not display anything. But this code DOES display something
Code:
<script type="text/javascript" charset="utf-8"> document.write({Question1}); </script>
Can someone help me to know what is going on with this? Is this possible to do? Or do you always have to input the QID literally, and not use text manipulation with variables? Thanks
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10611
- Thank you received: 3691
10 years 11 months ago #94130
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic javascript and variables in the QID
The problem is that Expression Manager parses the placeholders inside the curly braces at the server level so you won't get JavaScript objects, you will just get strings.
Additionally, you can't use JavaScript variable in the Expression Manager placeholders.
Additionally, you can't use JavaScript variable in the Expression Manager placeholders.
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- sys_sby01
- Offline
- New Member
Less
More
- Posts: 14
- Thank you received: 0
10 years 11 months ago #94131
by sys_sby01
Replied by sys_sby01 on topic javascript and variables in the QID
Hello Tony,
Is it possible to use expression Manager (EM) in Javascript
if it is possible, how to do it?
Thank you very much
Regards
Sys_sby
Is it possible to use expression Manager (EM) in Javascript
if it is possible, how to do it?
Thank you very much
Regards
Sys_sby
The topic has been locked.
- DenisChenu
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13907
- Thank you received: 2546
10 years 11 months ago #94141
by DenisChenu
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.
Replied by DenisChenu on topic javascript and variables in the QID
Is
Yes:
$('#question{QID}').hide();
or
if({Q1.NAOK}=="Y") if Q1 is in another group (before the script).
But no for:
if({Q1.NAOK}=="Y") if Q1 is in the same page.
Denis
Yes, or no ....it possible to use expression Manager (EM) in Javascript
if it is possible, how to do it?
Yes:
$('#question{QID}').hide();
or
if({Q1.NAOK}=="Y") if Q1 is in another group (before the script).
But no for:
if({Q1.NAOK}=="Y") if Q1 is in the same page.
Denis
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.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10611
- Thank you received: 3691
10 years 11 months ago #94149
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic javascript and variables in the QID
Yes, as Denis points out, EM can only be used to return strings if the EM variable is available before the page loads. So, his first example would actually be rendered as $('#question123').hide(); in the source.
Another note - EM is not parsed at all in template.js.
Another note - EM is not parsed at all in template.js.
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- sys_sby01
- Offline
- New Member
Less
More
- Posts: 14
- Thank you received: 0
10 years 11 months ago #94150
by sys_sby01
Replied by sys_sby01 on topic javascript and variables in the QID
Hello Denis/Tony,
Thanks for reply
In Javascript, Is it possible to get question number automatically by expression manager: {Qcode.qid}, so the script as like a below: $('#question{Q123.qid}').hide();
Thank you very much
Regards
Sys_sby
Thanks for reply
In Javascript, Is it possible to get question number automatically by expression manager: {Qcode.qid}, so the script as like a below: $('#question{Q123.qid}').hide();
Thank you very much
Regards
Sys_sby
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10611
- Thank you received: 3691
10 years 11 months ago #94152
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic javascript and variables in the QID
Yes but it would be safer to use:
The {Qcode.qid} variable doesn't seem to work for question types with sub-questions (arrays, etc.)
Code:
$('#question{that.Q123.qid}').hide();
The {Qcode.qid} variable doesn't seem to work for question types with sub-questions (arrays, etc.)
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- DenisChenu
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13907
- Thank you received: 2546
10 years 11 months ago #94163
by DenisChenu
Seems to work great everywhere. For sub question line use {SGQ}SQ01, {SGQ}SQ02 etc ...
Denis
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.
Replied by DenisChenu on topic javascript and variables in the QID
Think it's more easy to use directly {QID} and {SGQ}tpartner wrote: Yes but it would be safer to use:
Code:$('#question{that.Q123.qid}').hide();
The {Qcode.qid} variable doesn't seem to work for question types with sub-questions (arrays, etc.)
Seems to work great everywhere. For sub question line use {SGQ}SQ01, {SGQ}SQ02 etc ...
Denis
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.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10611
- Thank you received: 3691
10 years 11 months ago - 10 years 11 months ago #94165
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic javascript and variables in the QID
No, not everywhere. See attached image and survey.Seems to work great everywhere.
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
Last edit: 10 years 11 months ago by tpartner.
The topic has been locked.
- DenisChenu
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13907
- Thank you received: 2546
10 years 11 months ago - 10 years 11 months ago #94166
by DenisChenu
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.
Replied by DenisChenu on topic javascript and variables in the QID
Oh, you're right, in another question type need that for subquestion, or use QCODE_SQ1.qid then it take the qid of the parent question.
For exemple:
{ARRAY_SQ1==ARRAY_SQ2} is allways true.
Denis
PS: when i say work great everywhere, speaking of {QID} and {SGQ}. It's the only EM who don't change if you change the question type.
For exemple:
{ARRAY_SQ1==ARRAY_SQ2} is allways true.
Denis
PS: when i say work great everywhere, speaking of {QID} and {SGQ}. It's the only EM who don't change if you change the question type.
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.
Last edit: 10 years 11 months ago by DenisChenu.
The topic has been locked.