Welcome to the LimeSurvey Community Forum

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

populate different questions from javascript output

  • Leonmax
  • Leonmax's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 8 months ago - 1 year 8 months ago #241124 by Leonmax
Hey,
I am completly new to limesurvey. Maybe someone can help me with my problem. 

I have a javascriptcode, generating 10 random arrays (all with 3 items). They depend on eachother, thus the random selection for all of the arrays needs to happen in one function. Now i want to populate 5 singlechoice questions, with 2 arrays each. Is there a way to do this in limesurvey. I would be thankful if you could help me in any way.


 
Last edit: 1 year 8 months ago by Leonmax.

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 8 months ago #241132 by tpartner
We need more details, I don't know what you mean by "populate 5 singlechoice questions". Trigger clicks on radios?

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: Leonmax

Please Log in to join the conversation.

  • Leonmax
  • Leonmax's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 8 months ago #241134 by Leonmax
Thanks alot for the anwer! and sorry for my question being incomplete.
Hope this helps to clarify:

Trigger clicks on radios is right. I have a javasript code generating 10 random arrays (3 items each) from the same pool (pool contains of three arrays).
I generated with JS 10 arrays named choiceA1, choicheB1, choiceA2, choiceB2 etc.
Now the participants should choose 5 times between

choiceA1 or choiceB1

choiceA2 or choiceB2

I would be glad if you could helpt me with any advise

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 8 months ago #241135 by Joffm
Hi,
I advise you send this part of your survey with the script and examples of the"choice" questions as lss export.
I am still confused in which way you use the term "array".
To me it seems to be something like "conjoint".

Joffm 

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: Leonmax

Please Log in to join the conversation.

  • Leonmax
  • Leonmax's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 8 months ago #241136 by Leonmax
Hey,
again sorry for the confusion. 
I have attached my example. I am still in an early stage of  the generation. If my idea  (I dont have experience with JS and surveys in general)  for the generation of the survey does not make any sense and you would advise me to start from sratch, that would be helpful feedback as well. My survey will be a conjoint-analysis. With 'array' I just reffered to the datatype my JS code was generatig. 

Please Log in to join the conversation.

  • Leonmax
  • Leonmax's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 8 months ago #241137 by Leonmax
 

File Attachment:

File Name: limesurvey...3-04.lss
File Size:33 KB

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 8 months ago - 1 year 8 months ago #241138 by Joffm
Hi,

As far as I understand you want to do something like this:
Display two options
Here the "old" apple - banana example
 
Or you display like this
 

or this (with slider to display well on smartphones)
 


Here some threads about it
[url] forums.limesurvey.org/index.php/forum/ca...wer-options-in-a-box [/url]


So, this is easy, and there are many examples here in the forum.

And your "script" selects the displayed values of the two options, right?
I should say, create a question of type "array(text)" which you fill with the results of your script.

Here as example a script that selects randomly 5 numbers out of 500 and stores them into a question of type "multiple short text"
Code:
<script type="text/javascript" charset="utf-8">
function shuffle(array) {
 var currentIndex = array.length, temporaryValue, randomIndex;
 // While there remain elements to shuffle...
 while (0 !== currentIndex) {
 // Pick a remaining element...
 randomIndex = Math.floor(Math.random() * currentIndex);
 currentIndex -= 1;
 // And swap it with the current element.
 temporaryValue = array[currentIndex];
 array[currentIndex] = array[randomIndex];
 array[randomIndex] = temporaryValue;
 }
 return array;
}
 $(document).on('ready pjax:scriptcomplete',function(){
// Fill the array, hier Zahlen von 1 - 500
 var arr = ;
 for (var i = 1; i < 501; i++) {
 arr.push(i);
 }
 arr = shuffle(arr);
 $('#question{QID} input[type="text"]:eq(0)').val(arr[0]);
 $('#question{QID} input[type="text"]:eq(1)').val(arr[1]);
 $('#question{QID} input[type="text"]:eq(2)').val(arr[2]);
 $('#question{QID} input[type="text"]:eq(3)').val(arr[3]);
 $('#question{QID} input[type="text"]:eq(4)').val(arr[4]);
 $('#question{QID}').hide();
 });
</script>

Joffm

P.S.
And please show how you want your question  look like.

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 1 year 8 months ago by Joffm.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 8 months ago - 1 year 8 months ago #241139 by Joffm
Now again the question to understand your approach.
You said earlier

I have a javasript code generating 10 random arrays (3 items each) from the same pool

I do not see anything of random generation in your script (not to mention that it will not work in LimeSurvey)
There is an array choice1A = ["Option 1A", "Option 2A", "Option 3A"];
Does this mean these options are randomly selected values (apple or pear or banana or cherry...) out of a pool?

So that there can be
choice1A ["apple", "Ferrari", "London"]
choice1B ["banana", "Toyota", "Paris"]

And you generate 5 of these pairs which are displayed in 5 questions

Here I have three pools with ten options each.
And I generate ten arrays with randomly selected options from this pool.
 var arr1 = ["1A","1B","1C","1D", "1E", "1F","1G","1H","1I","1J"];
 var arr2 = ["2A","2B","2C","2D", "2E", "2F","2G","2H","2I","2J"];
 var arr3 = ["3A","3B","3C","3D", "3E", "3F","3G","3H","3I","3J"];

 

which I can use to fill my question.

If I misunderstood completely, please explain.

Show examples of your (10) "arrays", show the design of your question(s)!
You still are very vague.

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 1 year 8 months ago by Joffm.

Please Log in to join the conversation.

  • Leonmax
  • Leonmax's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 8 months ago #241140 by Leonmax
Hi,
this is really akward, but I exportet the survey without the sourcecode i was talking about. In the survey attached to this post it to be found under  [G01Q01]
despite my confused explanations you figured out my problems. 
in your last post. I want to generate 10 choicesets out of the three pools: 

const poolA = ["A1", "A2", "A3", "A4"];
const poolB = ["B1", "B2", "B3", "B4"];
const poolC = ["C1", "C2", "C3", "C4", "C5", "C6", "C7", "C8", "C9", "C10", "C11", "C12"];

The choice sets, randomly generated, might look like:

Question 1: Would you rather?: 
(choiceA1)["C1", "A1", "B2"] or (choiceB1)["C12", "A1", "B2"]

Question 2: Would you rather?:
(choiceA2)["C5", "A3", "B2"] or  (choiceB2)["C3", "A2", "B1"]

As said, the generation of these sets can be found in the source code below this post 

File Attachment:

File Name: limesurvey...4516.lss
File Size:44 KB



 

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 8 months ago #241143 by Joffm
Yes, now the script was included.

Well, here a solution. 
Two easy ways to display
1. list(radio)
2. array


Final layout up to you.

 

File Attachment:

File Name: limesurvey...5161.lss
File Size:70 KB


Joffm


 

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: Leonmax

Please Log in to join the conversation.

  • Leonmax
  • Leonmax's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 8 months ago #241145 by Leonmax
That works perfectly. Thank you so much!

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose