Bienvenue, Invité
Nom d'utilisateur : Mot de passe : Se souvenir de moi

SUJET : javascript and variables in the QID

javascript and variables in the QID il y a 1 an 4 semaines #94117

  • rodriguezm1
  • Portrait de rodriguezm1
  • Hors ligne
  • Fresh Lemon
  • Messages : 10
  • Karma: 0
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:
<script type="text/javascript" charset="utf-8">
var i = 1; 
var theQID = "{Question" + i + ".answer}";
document.write(theQID);
</script>

I also tried
<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
<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
L'administrateur a désactivé l'accès en écriture pour le public.

javascript and variables in the QID il y a 1 an 4 semaines #94130

  • tpartner
  • Portrait de tpartner
  • Hors ligne
  • LimeSurvey Team
  • Messages : 3813
  • Remerciements reçus 683
  • Karma: 328
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.
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
L'administrateur a désactivé l'accès en écriture pour le public.

javascript and variables in the QID il y a 1 an 4 semaines #94131

  • sys_sby
  • Portrait de sys_sby
  • Hors ligne
  • Junior Lime
  • Messages : 23
  • Karma: 0
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
L'administrateur a désactivé l'accès en écriture pour le public.

javascript and variables in the QID il y a 1 an 4 semaines #94141

  • DenisChenu
  • Portrait de DenisChenu
  • Hors ligne
  • Moderator Lime
  • Messages : 5845
  • Remerciements reçus 715
  • Karma: 222
Is
it possible to use Expression Manager (EM) in Javascript
if it is possible, how to do it?
Yes, or no ....

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
L'administrateur a désactivé l'accès en écriture pour le public.

javascript and variables in the QID il y a 1 an 4 semaines #94149

  • tpartner
  • Portrait de tpartner
  • Hors ligne
  • LimeSurvey Team
  • Messages : 3813
  • Remerciements reçus 683
  • Karma: 328
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.
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
L'administrateur a désactivé l'accès en écriture pour le public.

javascript and variables in the QID il y a 1 an 4 semaines #94150

  • sys_sby
  • Portrait de sys_sby
  • Hors ligne
  • Junior Lime
  • Messages : 23
  • Karma: 0
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
L'administrateur a désactivé l'accès en écriture pour le public.

javascript and variables in the QID il y a 1 an 3 semaines #94152

  • tpartner
  • Portrait de tpartner
  • Hors ligne
  • LimeSurvey Team
  • Messages : 3813
  • Remerciements reçus 683
  • Karma: 328
Yes but it would be safer to use:
$('#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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
L'administrateur a désactivé l'accès en écriture pour le public.

javascript and variables in the QID il y a 1 an 3 semaines #94163

  • DenisChenu
  • Portrait de DenisChenu
  • Hors ligne
  • Moderator Lime
  • Messages : 5845
  • Remerciements reçus 715
  • Karma: 222
tpartner écrit:
Yes but it would be safer to use:
$('#question{that.Q123.qid}').hide();

The {Qcode.qid} variable doesn't seem to work for question types with sub-questions (arrays, etc.)
Think it's more easy to use directly {QID} and {SGQ}

Seems to work great everywhere. For sub question line use {SGQ}SQ01, {SGQ}SQ02 etc ...

Denis
L'administrateur a désactivé l'accès en écriture pour le public.

javascript and variables in the QID il y a 1 an 3 semaines #94165

  • tpartner
  • Portrait de tpartner
  • Hors ligne
  • LimeSurvey Team
  • Messages : 3813
  • Remerciements reçus 683
  • Karma: 328
Seems to work great everywhere.
No, not everywhere. See attached image and survey.

Capture_2013-03-23.JPG


Fichier attaché :

Nom du fichier : limesurvey_survey_846179.lss
Taille du ficher : 20 KB
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
Dernière édition: il y a 1 an 3 semaines par tpartner.
L'administrateur a désactivé l'accès en écriture pour le public.

javascript and variables in the QID il y a 1 an 3 semaines #94166

  • DenisChenu
  • Portrait de DenisChenu
  • Hors ligne
  • Moderator Lime
  • Messages : 5845
  • Remerciements reçus 715
  • Karma: 222
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.
Dernière édition: il y a 1 an 3 semaines par DenisChenu.
L'administrateur a désactivé l'accès en écriture pour le public.
Modérateurs: ITEd
Temps de génération de la page : 0.320 secondes
Donation Image