- Posts: 10
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Accessing Expressions via JavaScript
- umrosa
- Topic Author
- Offline
- New Member
Introduction:
I'm working on a complex project containing a large number of surveys. Since there is a number of workarounds and additional JS code required, I have created a custom theme for the project.
Ideally, I want to have all of the JS code in the theme and none in the surveys themselves, so the surveys can be created and maintained by people without JS knowledge.
My LS version is 3.22.25.
Problem:
I am trying to implement a function that creates a new html page with content from the previous pages of the survey (mostly question texts). This page is intended for the participant to print part of the survey or save it as a pdf.
What I would like to do is have a JS function that accesses the relevant content via QCode to write it into the new page. The required QCodes vary from survey to survey.
I know I can include LS Expressions in a block of script when I put it into a question. What I am doing at the moment is exactly that. The code looks something like this:
printFunction ( {Q1.question}, {Q5.question}, {Q7.question} );
printFunction2 ( {SID} );
Question:
Is it possible to access LimeSurvey Expressions via JavaScript? If so, how?
- DenisChenu
- Offline
- LimeSurvey Community Team
- Posts: 13643
- Thank you received: 2491
You can give the print answer url BEFORE survey is submitted
I use <a href="/index.php?r=printanswers/view&surveyid={SID}" target="_blank">Print your answers</a>
But you can force PDF too
<a href="/index.php?r=printanswers/view&surveyid={SID}&pdf=1">Export your answers as PDF</a>
Is it possible to access LimeSurvey Expressions via JavaScript? If so, how?
Yes : for variable before the current one
var myVar = '{Qcode.NAOK}';
If inside the same mage
<div id="myVar">{Qcode.NAOK}</div> <script>var myVar = $('#myVar').text()</script>
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.
- umrosa
- Topic Author
- Offline
- New Member
- Posts: 10
- Thank you received: 0
DenisChenu wrote: Your first question are unrelated to Expression and JS, no ?
You can give the print answer url BEFORE survey is submitted
I use <a href="/index.php?r=printanswers/view&surveyid={SID}" target="_blank">Print your answers</a>
But you can force PDF too
<a href="/index.php?r=printanswers/view&surveyid={SID}&pdf=1">Export your answers as PDF</a>
I want to create a pdf report that contains only some of the participant's answers. Also, I want to display text in the same design as within the survey.
So no, the "print answers" function is not what I'm looking for.
DenisChenu wrote:
Is it possible to access LimeSurvey Expressions via JavaScript? If so, how?
Yes : for variable before the current one
Code:var myVar = '{Qcode.NAOK}';
If inside the same mageCode:<div id="myVar">{Qcode.NAOK}</div> <script>var myVar = $('#myVar').text()</script>
This only works for script that is on the page, but I think I pointed out that I'm looking for a way to access LS Expressions from a JS function in the custom.js file of the theme.
- umrosa
- Topic Author
- Offline
- New Member
- Posts: 10
- Thank you received: 0
umrosa wrote: I will edit my post.
Wait, is it not possible to edit your own post?
Also, I'm noticing that when I'm writing a post, the text editor seems pretty messed up (layout-wise).
Is there a subforum for technical issues with the forum itself?
- DenisChenu
- Offline
- LimeSurvey Community Team
- Posts: 13643
- Thank you received: 2491
Then : you create a plugin ? You use a plugin ?umrosa wrote: I want to create a pdf report that contains only some of the participant's answers. Also, I want to display text in the same design as within the survey.
So no, the "print answers" function is not what I'm looking for.
With pdfReport plugin : you can use the url before survey it send, and you can force a PDF to be done with reset=1 in url.
gitlab.com/SondagesPro/ExportAndStats/pd...r/pdfReport.php#L424
Expression is related to Survey, custom.js to a lot of survey …umrosa wrote: This only works for script that is on the page, but I think I pointed out that I'm looking for a way to access LS Expressions from a JS function in the custom.js file of the theme.
I use sometimes in a twig file <div id="myvar" style='display:none' hidden=1>{MYVARIABLE.NAOK}</div>
And use it in custom.js, but it's clearly a workaround.
Report issue : community.limesurvey.org/bug-tracker/Is there a subforum for technical issues with the forum itself?
use LimeSurvey website category
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.
- umrosa
- Topic Author
- Offline
- New Member
- Posts: 10
- Thank you received: 0
Then : you create a plugin ? You use a plugin ?
With pdfReport plugin : you can use the url before survey it send, and you can force a PDF to be done with reset=1 in url.
gitlab.com/SondagesPro/ExportAndStats/pd...r/pdfReport.php#L424
Thanks for pointing me to that plugin. I had read about it somewhere else on the LS website, and I had gotten the impression it was only compatible up to v2.5 or something.
Maybe I can try to use it.
I would love to create a plugin myself, but I have no idea about how to actually do that. Is there any useful documentation about this?
Also, I only have frontend access to LS at the moment, so I'm trying to do everything in JS.
Expression is related to Survey, custom.js to a lot of survey …
Sure, I know, but I was hoping there was some kind of interface between JS and Expressions.
In the file "em_javascript", I found a function 'LEMval' that seemed to be what I was looking for. However, I don't know what to pass as a parameter to this function. QCode? SGQA-code? If SGQA-code: how to figure this out (in custom.js) when I only know the QCode?