- Posts: 15
- Thank you received: 0
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
- Topic Author
- Offline
- New Member
Less
More
5 years 6 months ago #175163
by artasom
Iterate over the responses of an array question into an array in javascript was created 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
. But I would like in a javascript to iterate over the answers instead of going one by one. Is this possible?
Thanks in advance.
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
Thanks in advance.
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10108
- Thank you received: 3593
5 years 6 months ago #175167
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 Iterate over the responses of an array question into an array in javascript
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
- Topic Author
- Offline
- New Member
Less
More
- Posts: 15
- Thank you received: 0
5 years 6 months ago #175168
by artasom
Replied by artasom on topic Iterate over the responses of an array question into an array in javascript
Save them in a javascript array to make some calculations afterwards
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10108
- Thank you received: 3593
5 years 6 months ago #175170
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 Iterate over the responses of an array question into an array in javascript
When placed in the source of an array-texts question, this script will load all answers in that question into a JavaScript array:
You will, of course, need something to fire it.
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
- Topic Author
- Offline
- New Member
Less
More
- Posts: 15
- Thank you received: 0
5 years 6 months ago #175172
by artasom
Replied by artasom on topic Iterate over the responses of an array question into an array in javascript
Thanks, I'll give a try!
The topic has been locked.