Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Iterate over the responses of an array question into an array in javascript

  • artasom
  • artasom's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
5 years 6 months ago #175163 by artasom
If this question has already been answered, my sincere apologies in advance. I have been trying to find it, to no avail. Maybe the terms I am using for my search are not the appropriate ones.
I have two questions, one is an array of texts and another an array of numbers. I know I can access through the expression manager to the answers via the code
Code:
Qcode__SQY1_SQX1
. But I would like in a javascript to iterate over the answers instead of going one by one. Is this possible?
Thanks in advance.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 6 months ago #175167 by tpartner
Iterate through them and do what?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • artasom
  • artasom's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
5 years 6 months ago #175168 by artasom
Save them in a javascript array to make some calculations afterwards
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 6 months ago #175170 by tpartner
When placed in the source of an array-texts question, this script will load all answers in that question into a JavaScript array:

Code:
$(document).on('ready pjax:scriptcomplete',function(){
  var myArray = [];
 
  $('#question{QID} input:text').each(function(i) {
    myArray.push($(this).val());
  });
 
  console.log(myArray);
});

You will, of course, need something to fire it.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • artasom
  • artasom's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
5 years 6 months ago #175172 by artasom
Thanks, I'll give a try!
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose