- Posts: 19
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Can I give a value to a question via JS?
- AritzP
- Topic Author
- Offline
- New Member
Less
More
4 years 5 months ago #189655
by AritzP
Can I give a value to a question via JS? was created by AritzP
Hi,
We are using a weighting formula for the scores of the survey, so we use Javascript instead of Expression Manager.
In Javascript, we have a variable value which is called 'valorTotal' and we want to give the value of this variable to the question. (The Javascript code is in the source option of the question)
There is a way to give the value of the variable to the question text, but the question doesn´t take the value, it only shows the value.
For example, in the farewell message, we need to take a question value, and depending of his weighted value, it shows a different result.
This doesn´t work, because the 'RINFO01' question, doesn´t have a value.
What I need is something like:
{RINFO01} = valorTotal;
I am using Limesurvey 3.17.7
Thanks for your time!
We are using a weighting formula for the scores of the survey, so we use Javascript instead of Expression Manager.
In Javascript, we have a variable value which is called 'valorTotal' and we want to give the value of this variable to the question. (The Javascript code is in the source option of the question)
There is a way to give the value of the variable to the question text, but the question doesn´t take the value, it only shows the value.
Code:
document.getElementById('answer5X339X2411').value = valorTotal;
For example, in the farewell message, we need to take a question value, and depending of his weighted value, it shows a different result.
Attachment not found
This doesn´t work, because the 'RINFO01' question, doesn´t have a value.
What I need is something like:
{RINFO01} = valorTotal;
I am using Limesurvey 3.17.7
Thanks for your time!
The topic has been locked.
- tpartner
- Away
- LimeSurvey Community Team
Less
More
- Posts: 10632
- Thank you received: 3697
4 years 5 months ago #189662
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 Can I give a value to a question via JS?
What question type is RINFO01?
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: AritzP
The topic has been locked.
- AritzP
- Topic Author
- Offline
- New Member
Less
More
- Posts: 19
- Thank you received: 0
4 years 5 months ago #189663
by AritzP
Replied by AritzP on topic Can I give a value to a question via JS?
Is an equation question.
I tried using it as a numerical input question, so I could give the variable value to the text, but the question didnt´t get it as value.
I tried using it as a numerical input question, so I could give the variable value to the text, but the question didnt´t get it as value.
The topic has been locked.
- DenisChenu
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13935
- Thank you received: 2551
4 years 5 months ago #189669
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 Can I give a value to a question via JS?
Never use an equation question for javascript workaround.
Expression Manager update it when move next.
Else : since you dodn't show any code part and give such a little information …
Expression Manager update it when move next.
Else : since you dodn't show any code part and give such a little information …
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 topic has been locked.
- tpartner
- Away
- LimeSurvey Community Team
Less
More
- Posts: 10632
- Thank you received: 3697
4 years 5 months ago #189678
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 Can I give a value to a question via JS?
This script in the source of a numeric input question will load that input and fire Expression Manager:
Code:
<script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:scriptcomplete',function(){ var thisQuestion = $('#question{QID}'); // Load a value into the question input var valorTotal = 15.50; $('input:text', thisQuestion).val(valorTotal ).trigger('keyup'); }); </script>
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
The following user(s) said Thank You: DenisChenu, gabrieljenik, AritzP
The topic has been locked.
- AritzP
- Topic Author
- Offline
- New Member
Less
More
- Posts: 19
- Thank you received: 0
4 years 5 months ago #189709
by AritzP
Replied by AritzP on topic Can I give a value to a question via JS?
Hi tpartner,
I have no words to describe my thanks.
I am very grateful for all your help!!
I have no words to describe my thanks.
I am very grateful for all your help!!
The topic has been locked.