Getting the token from javascript

More
2 weeks 22 hours ago #187475 by LarryMartell
Is there a way to access the survey token from my javascript code?

Please Log in or Create an account to join the conversation.

LimeSurvey Partners
More
2 weeks 21 hours ago #187476 by jelo
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.

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

Please Log in or Create an account to join the conversation.

More
2 weeks 10 hours ago #187495 by LarryMartell
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

Please Log in or Create an account to join the conversation.

More
2 weeks 10 hours ago #187496 by jelo
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

Please Log in or Create an account to join the conversation.

More
2 weeks 10 hours ago #187498 by LarryMartell
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.

Please Log in or Create an account to join the conversation.

More
2 weeks 10 hours ago - 4 days 10 hours ago #187499 by tpartner
{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.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com
Last edit: 4 days 10 hours ago by tpartner.

Please Log in or Create an account to join the conversation.

More
2 weeks 9 hours ago #187503 by jelo

LarryMartell wrote: Not sure what you mean by your question.

Tpartner answered that nicely. Sorry, that I didn't realized you're using an external script.

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users

Please Log in or Create an account to join the conversation.

More
2 weeks 9 hours ago #187505 by LarryMartell
Ah, the token is in the URL and I can get that in the JS.

Please Log in or Create an account to join the conversation.

More
2 weeks 9 hours ago #187506 by tpartner
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.
Official LimeSurvey Partner - partnersurveys.com

Please Log in or Create an account to join the conversation.

More
2 weeks 6 hours ago #187510 by LarryMartell
What about the attributes? Can I access those in my JS?

Please Log in or Create an account to join the conversation.

More
2 weeks 5 hours ago #187513 by tpartner
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.
Official LimeSurvey Partner - partnersurveys.com

Please Log in or Create an account to join the conversation.

More
4 days 11 hours ago #187752 by DenisChenu
Easy way : add a javascript function in github.com/LimeSurvey/LimeSurvey/blob/ma...r/custom_header.twig

Something like
<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 .
An error happen ? Before make a new topic : remind the Debug mode .
The following user(s) said Thank You: tpartner

Please Log in or Create an account to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!