- Posts: 38
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Getting the token from javascript
- LarryMartell
- Topic Author
- Offline
- Junior Member
Less
More
4 years 8 months ago #187475
by LarryMartell
Getting the token from javascript was created by LarryMartell
Is there a way to access the survey token from my javascript code?
The topic has been locked.
- jelo
- Offline
- Platinum Member
Less
More
- Posts: 5033
- Thank you received: 1257
4 years 8 months ago #187476
by jelo
The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
Replied by jelo on topic Getting the token from javascript
Expression script (aka ExpressionManager) variables are available as strings inside javascript. No objects.
Where do you run your Javascript? Try to assign {TOKEN} as a string to a javascript variable inside your JS code.
Where do you run your Javascript? Try to assign {TOKEN} as a string to a javascript variable inside your JS code.
The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
The following user(s) said Thank You: DenisChenu
The topic has been locked.
- LarryMartell
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 38
- Thank you received: 0
4 years 8 months ago #187495
by LarryMartell
Replied by LarryMartell on topic Getting the token from javascript
Not sure what you mean by your question. In the browser source tab the JS is running from tmp/assets. Accessing TOKEN gives Uncaught ReferenceError: TOKEN is not defined
The topic has been locked.
- jelo
- Offline
- Platinum Member
Less
More
- Posts: 5033
- Thank you received: 1257
4 years 8 months ago #187496
by jelo
The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
Replied by jelo on topic Getting the token from javascript
What version of LimeSurvey is used? Might be a bug or something was changed in a newer version. Is the Survey activated when you test TOKEN?
The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
The topic has been locked.
- LarryMartell
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 38
- Thank you received: 0
4 years 8 months ago #187498
by LarryMartell
Replied by LarryMartell on topic Getting the token from javascript
Version 2.73.1+171220. Yes I am taking the survey and I have a break point set in the JS code $(document).ready function and I am checking it there in the debugger.
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10108
- Thank you received: 3593
4 years 8 months ago - 4 years 8 months ago #187499
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 Getting the token from javascript
{TOKEN} like all placeholders is rendered at the server level so is only available in JS placed in survey text elements, questions group descriptions or theme TWIG files.
Placeholders are not available in the custom.js file and, unless previously defined, the console.
Placeholders are not available in the custom.js file and, unless previously defined, the console.
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 4 years 8 months ago by tpartner.
The topic has been locked.
- jelo
- Offline
- Platinum Member
Less
More
- Posts: 5033
- Thank you received: 1257
4 years 8 months ago #187503
by jelo
The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
Replied by jelo on topic Getting the token from javascript
Tpartner answered that nicely. Sorry, that I didn't realized you're using an external script.LarryMartell wrote: Not sure what you mean by your question.
The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
The topic has been locked.
- LarryMartell
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 38
- Thank you received: 0
4 years 8 months ago #187505
by LarryMartell
Replied by LarryMartell on topic Getting the token from javascript
Ah, the token is in the URL and I can get that in the JS.
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10108
- Thank you received: 3593
4 years 8 months ago #187506
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 Getting the token from javascript
That will probably only work on the first screen or if using AJAX mode (which I advise against).
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- LarryMartell
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 38
- Thank you received: 0
4 years 8 months ago #187510
by LarryMartell
Replied by LarryMartell on topic Getting the token from javascript
What about the attributes? Can I access those in my JS?
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10108
- Thank you received: 3593
4 years 8 months ago #187513
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 Getting the token from javascript
Token attributes are rendered exactly the same as the token.
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
- Away
- LimeSurvey Community Team
Less
More
- Posts: 13643
- Thank you received: 2491
4 years 8 months ago #187752
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 Getting the token from javascript
Easy way : add a javascript function in
github.com/LimeSurvey/LimeSurvey/blob/ma...r/custom_header.twig
Something like
Something like
Code:
<script> var token = "{TOKEN}"; var surveyId = "{SID}"; var yourVarComeFromSurvey = "{QuestionCode}"; </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.
The following user(s) said Thank You: tpartner
The topic has been locked.