- Posts: 2
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Saving a Javascript variable in LimeSurvey
- Feloux
- Topic Author
- Offline
- New Member
Less
More
8 years 11 months ago #118774
by Feloux
Saving a Javascript variable in LimeSurvey was created by Feloux
Hello everybody,
I have a question that looks pretty simple to me but I haven't managed to find an answer.
Let's say, with source code of a question, I managed to put a Tetris game in a limesurvey question. I would love to be able to save the number of lines (which is a variable in my javascript code), but I don't know how to do it.
So my variable would be 'Lines' I would like to store as the answer of the question this precise number of lines.
Is it possible ? Would I be able to do the same if I had several variables to save ?
Thanks in advance,
Félix
PS : I'll post my code if requested, but I don't think it's relevant
I have a question that looks pretty simple to me but I haven't managed to find an answer.
Let's say, with source code of a question, I managed to put a Tetris game in a limesurvey question. I would love to be able to save the number of lines (which is a variable in my javascript code), but I don't know how to do it.
So my variable would be 'Lines' I would like to store as the answer of the question this precise number of lines.
Is it possible ? Would I be able to do the same if I had several variables to save ?
Thanks in advance,
Félix
PS : I'll post my code if requested, but I don't think it's relevant
The topic has been locked.
- Ben_V
- Offline
- Platinum Member
Less
More
- Posts: 1223
- Thank you received: 351
8 years 11 months ago #118776
by Ben_V
Benoît
EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)
Replied by Ben_V on topic Saving a Javascript variable in LimeSurvey
If 'Lines' is a javascript variable previously defined in the page, you can use a (hidden or not) numerical question to store this value. Just paste in the source of the question:
Code:
<script type="text/javascript"> jQuery(document).ready(function() { $(".numeric:eq(0) input.text").val(Lines); }); </script>
Benoît
EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)
The following user(s) said Thank You: Feloux
The topic has been locked.
- Feloux
- Topic Author
- Offline
- New Member
Less
More
- Posts: 2
- Thank you received: 0
8 years 11 months ago #118979
by Feloux
Replied by Feloux on topic Saving a Javascript variable in LimeSurvey
Hello,
Thank you very much for your answer Benoît.
I've looked and tried a lot of different things but none of them are working. So, the idea is simply that the JS variable appears in the result of the survey ! Here I take the simplest code possible :
It's obviously not a real question, but at the end, when we are looking at the answers we should see the value '4' right ?
But it is not working.
Thanks in advance for any help someone will give me.
Félix
Thank you very much for your answer Benoît.
I've looked and tried a lot of different things but none of them are working. So, the idea is simply that the JS variable appears in the result of the survey ! Here I take the simplest code possible :
Code:
<script type="text/javascript"> var Lines = 4; jQuery(document).ready(function() { $(".numeric:eq(0) input.text").val(Lines); }); </script>
It's obviously not a real question, but at the end, when we are looking at the answers we should see the value '4' right ?
But it is not working.
Thanks in advance for any help someone will give me.
Félix
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10612
- Thank you received: 3691
8 years 11 months ago - 8 years 11 months ago #118982
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 Saving a Javascript variable in LimeSurvey
Try placing this in the source of a short-text question.
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function(){ var Lines = 4; $('#question{QID} input[type="text"]').val(Lines); }); </script>
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 8 years 11 months ago by tpartner.
The following user(s) said Thank You: Ben_V
The topic has been locked.