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

More
1 week 6 days ago #175163 by artasom
artasom created the topic: Iterate over the responses of an array question into an array in javascript
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
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.

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

More
1 week 6 days ago #175167 by tpartner
tpartner replied the 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.

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

More
1 week 6 days ago #175168 by artasom
artasom replied the 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

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

More
1 week 6 days ago #175170 by tpartner
tpartner replied the 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:

$(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.

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

More
1 week 6 days ago #175172 by artasom
artasom replied the topic: Iterate over the responses of an array question into an array in javascript
Thanks, I'll give a try!

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!