Welcome to the LimeSurvey Community Forum

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

Just show one question from randomized group, hide the others

  • mr2jswe
  • mr2jswe's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
12 years 1 week ago #78437 by mr2jswe
Im guessing I should use the Relevance field for each question, in combination with the random_group command somehow?

How can I show just one randomized question, out of the five Ive got in the same group?
The topic has been locked.
  • mr2jswe
  • mr2jswe's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
12 years 1 week ago #78438 by mr2jswe
In "Relevance equation:" field Im trying:

'rand_dim1'==25659X12X76

..where rand_dim1 is the Randomization group name for the selected group. Not working though.
The topic has been locked.
  • mr2jswe
  • mr2jswe's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
12 years 1 week ago #78481 by mr2jswe
I found the answer here , under Random question sets.

However it does not seem to work when I use Survey format All in One, instead of Group by Group. When I do, only one of the groups get properly randomized.

I'm trying to get 1 random question displayed per group, on the same page.
(I have 3 different groups each containing five questions)

Thanks.
The topic has been locked.
  • Mazi
  • Mazi's Avatar
  • Offline
  • Official LimeSurvey Partner
  • Official LimeSurvey Partner
More
12 years 4 days ago #78650 by Mazi
TRy the following workaround:
1. Create an additional question for each group.
2. Use Javascript to fill the question with a random number between 1-X. There are several examples at the forums and maybe also at manual -> workarounds -> Javascript. X is the number of questions at your group.
3. Hide the question using Javascript by adding this to the question text in source code mode of the editor:
<script>
$(document).ready(function()
{
$('#question4444').hide();
});
</script>
-> replace 4444 with your question ID

4. Set conditions to each question of the group to only show up "IF question X (this we fill with the random number) equals Y".

Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
The topic has been locked.
  • mr2jswe
  • mr2jswe's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
12 years 4 days ago - 12 years 4 days ago #78686 by mr2jswe
Thankyou, I have followed your steps closely, and added an extra question to each group. To add a random number to that extra question I followed these instructions , however for some reason that code didnt work, but this does:

<script>
$(document).ready(function()
{
// Find a random number between 1 and 3
var randNumber = Math.floor(Math.random()*3 + 1);
// Populate and hide the hidden question
$('input#answer12739X17X94').val(randNumber);
$('#question94').hide();
});
</script>

It populates the question with random number between 1 and 3, so far so good. It fills in the number in a short text field so I can see it. (as long as I dont hide the question)

Now I try to create conditions for the rest of the questions in the group, depending on the random number I created in the first (hidden) question. I use "Set conditions for this question", choose from "Previous questions" the first hidden question, then "Equals", as an Answer I choose "Constant" and enters the value 1 for the first question.

My logic here being that the random numbers 1-3 corresponds to questions 1-3.

When saved I can see in Relevance for the question: ((G1RAND.NAOK == "1")) (G1RAND being the hidden question) However this doesnt work. Somehow the conditions doesnt get recognized, and the questions never show up.

I am stuck at the last step, what am I doing wrong?
Thanks!
Last edit: 12 years 4 days ago by mr2jswe. Reason: spelling
The topic has been locked.
  • mr2jswe
  • mr2jswe's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
12 years 4 days ago #78687 by mr2jswe
In a subsequent question, I try to reproduce the randomized number from the earlier question through {INSERTANS:12739X17X94} but nothing shows up. Also when I use button "LimeSurvey replacement field properties" and insert from "Previous answer fields" I get {Null} as a result.

I should be able to reproduce it right?
The topic has been locked.
  • TMSWhite
  • TMSWhite's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
12 years 4 days ago - 12 years 4 days ago #78688 by TMSWhite
You can do it this way, using built-in Expression Manager functionality and not requiring any custom JavaScript.

This sample survey has 5 groups of questions with 6 questions each. In G0, the first group, there are 5 hidden equation questions, called ask1-ask5, each of which sets a random variable using
Code:
{floor(rand(1,6.9999))}

to get a random number between 1 and 6. Then, the relevance for each question in the group is something like:
Code:
ask1==3

So, this survey pre-randomizes which questions should be shown, and each time you visit a group (e.g. if you use the navigation index to return to a question), you'll see the same randomized question; but each person who completes the survey will have a different set of random questions.

File Attachment:

File Name: limesurvey...5164.lss
File Size:113 KB


This survey is in group-at-a-time format, but it works just fine in all-in-one mode and question-by-question mode too.
Last edit: 12 years 4 days ago by TMSWhite.
The following user(s) said Thank You: mr2jswe
The topic has been locked.
  • mr2jswe
  • mr2jswe's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
12 years 4 days ago #78689 by mr2jswe
I just checked it out, and it looks like you solved it spot on! Its a MUCH cleaner solution aswell. My hat goes off for you Mr. White, thank you so much!

Johnny
The topic has been locked.
  • TMSWhite
  • TMSWhite's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
12 years 4 days ago #78690 by TMSWhite
You are welcome. Mazi, I added this example to the documentation here .
The topic has been locked.
  • mr2jswe
  • mr2jswe's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
12 years 4 days ago #78691 by mr2jswe
Here is my smaller survey, same solution as yours, referring to the PM and email I sent you.

File Attachment:

File Name: limesurvey...5363.lss
File Size:31 KB
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose