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
  • AritzP's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 5 months ago #189655 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.

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
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 5 months ago #189662 by tpartner
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
  • AritzP's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
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.
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 5 months ago #189669 by DenisChenu
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 …

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
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 5 months ago #189678 by tpartner
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>

File Attachment:

File Name: limesurvey...0-08.lss
File Size:15 KB

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: DenisChenu, gabrieljenik, AritzP
The topic has been locked.
  • AritzP
  • AritzP's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
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!!
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose