- Posts: 5
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
SGQA shortcut for reference via javascript / jquery on final page?
- McdanielMackenzie
- Topic Author
- Offline
- New Member
Less
More
10 years 11 months ago #95248
by McdanielMackenzie
SGQA shortcut for reference via javascript / jquery on final page? was created by McdanielMackenzie
Hi. I'm doing some modularization of surveys over here. Key to that is the ability to not custom code the javascript as much as possible - rather, I would prefer to have something more generic that can be applied to different surveys regardless of the SGQA.
To whit... is there a shortcut? More specifically, I'm calling an ajax function on the final screen (embedded in the end message, actually).
I want to reference 3 fields that were populated earlier in the survey. While I could reference via SGQA, the survey, groups, questions, etc... are being generated dynamically so I'd prefer not to track S / G / Q / A variables for each survey if I can help it. I'd really like to be able to do something along the lines of $('#foo').val() with #foo being the question 'code' used during question creation.
Is this possible?
Thanks.
("...he waits anxiously, hopeful, yet still fearful of bad news...")
To whit... is there a shortcut? More specifically, I'm calling an ajax function on the final screen (embedded in the end message, actually).
I want to reference 3 fields that were populated earlier in the survey. While I could reference via SGQA, the survey, groups, questions, etc... are being generated dynamically so I'd prefer not to track S / G / Q / A variables for each survey if I can help it. I'd really like to be able to do something along the lines of $('#foo').val() with #foo being the question 'code' used during question creation.
Is this possible?
Thanks.
("...he waits anxiously, hopeful, yet still fearful of bad news...")
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10632
- Thank you received: 3697
10 years 11 months ago - 10 years 11 months ago #95258
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 SGQA shortcut for reference via javascript / jquery on final page?
You can use
Expression Manager variables
in the end message.
So, assuming the question code is foo, if you want to pipe in the answer code, something like this should work:
Or, if you want to pipe in the answer label:
So, assuming the question code is foo, if you want to pipe in the answer code, something like this should work:
Code:
{foo.value}
Or, if you want to pipe in the answer label:
Code:
{foo.shown}
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 10 years 11 months ago by tpartner.
The topic has been locked.
- McdanielMackenzie
- Topic Author
- Offline
- New Member
Less
More
- Posts: 5
- Thank you received: 0
10 years 11 months ago #95276
by McdanielMackenzie
Replied by McdanielMackenzie on topic SGQA shortcut for reference via javascript / jquery on final page?
Sweet. Thanks. That's perfect. I haven't done anything with expressions (they look daunting). Time to tackle it.
I appreciate your assistance.
I appreciate your assistance.
The topic has been locked.
- McdanielMackenzie
- Topic Author
- Offline
- New Member
Less
More
- Posts: 5
- Thank you received: 0
10 years 11 months ago - 10 years 11 months ago #95282
by McdanielMackenzie
Replied by McdanielMackenzie on topic SGQA shortcut for reference via javascript / jquery on final page?
For the next person who finds this useful - as a hint, you may need to escape using quotes. For example, if there's a question with code "foo", the following displays the value in the console:
My point being that the above would break without the double-quotes encapsulating the expression var.
Hope this helps someone!
Code:
<script> console.log("{foo.value}"); </script>
Hope this helps someone!
Last edit: 10 years 11 months ago by McdanielMackenzie. Reason: to fix a typo
The topic has been locked.