Welcome, Guest
Username: Password:
  • Page:
  • 1
  • 2

TOPIC: Just show one question from randomized group, hide the others

Just show one question from randomized group, hide the others 4 years 1 month ago #78437

  • mr2jswe
  • mr2jswe's Avatar
  • Offline
  • Junior Lime
  • Posts: 22
  • Karma: 0
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 administrator has disabled public write access.

Just show one question from randomized group, hide the others 4 years 1 month ago #78438

  • mr2jswe
  • mr2jswe's Avatar
  • Offline
  • Junior Lime
  • Posts: 22
  • Karma: 0
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 administrator has disabled public write access.

Just show one question from randomized group, hide the others 4 years 1 month ago #78481

  • mr2jswe
  • mr2jswe's Avatar
  • Offline
  • Junior Lime
  • Posts: 22
  • Karma: 0
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 administrator has disabled public write access.

Just show one question from randomized group, hide the others 4 years 1 month ago #78650

  • Mazi
  • Mazi's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5964
  • Thank you received: 363
  • Karma: 259
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
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)limesurvey.org'"
The administrator has disabled public write access.

Just show one question from randomized group, hide the others 4 years 1 month ago #78686

  • mr2jswe
  • mr2jswe's Avatar
  • Offline
  • Junior Lime
  • Posts: 22
  • Karma: 0
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: 4 years 1 month ago by mr2jswe. Reason: spelling
The administrator has disabled public write access.

Just show one question from randomized group, hide the others 4 years 1 month ago #78687

  • mr2jswe
  • mr2jswe's Avatar
  • Offline
  • Junior Lime
  • Posts: 22
  • Karma: 0
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 administrator has disabled public write access.

Just show one question from randomized group, hide the others 4 years 1 month ago #78688

  • TMSWhite
  • TMSWhite's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 758
  • Thank you received: 83
  • Karma: 37
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
{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:
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: 4 years 1 month ago by TMSWhite.
The administrator has disabled public write access.
The following user(s) said Thank You: mr2jswe

Just show one question from randomized group, hide the others 4 years 1 month ago #78689

  • mr2jswe
  • mr2jswe's Avatar
  • Offline
  • Junior Lime
  • Posts: 22
  • Karma: 0
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 administrator has disabled public write access.

Just show one question from randomized group, hide the others 4 years 1 month ago #78690

  • TMSWhite
  • TMSWhite's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 758
  • Thank you received: 83
  • Karma: 37
You are welcome. Mazi, I added this example to the documentation here.
The administrator has disabled public write access.

Just show one question from randomized group, hide the others 4 years 1 month ago #78691

  • mr2jswe
  • mr2jswe's Avatar
  • Offline
  • Junior Lime
  • Posts: 22
  • Karma: 0
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 administrator has disabled public write access.

Just show one question from randomized group, hide the others 4 years 1 month ago #78698

  • TMSWhite
  • TMSWhite's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 758
  • Thank you received: 83
  • Karma: 37
Your question was that the initial solution didn't seem to be saving the data properly to the database. My best guess is that rand() is being called more than once (e.g. when data is finalized, or when wanting to print the answers), so the set of relevant questions changes and you end up with missing data.

The solution is to ensure that the randomization is only called once. The logic for Group0 looks like this:



Note that the if() function first checks whether ask1 has already been set, and if so, uses that value. If the value hasn't been set, then it uses a random value to set the value of ask1.

Here is the replacement survey (although I removed the final summary report - you can confirm you have the proper data by activating the survey and checking that the print answers screen shows the proper values).

File Attachment:

File Name: limesurvey...4-15.lss
File Size:101 KB
The administrator has disabled public write access.
The following user(s) said Thank You: mr2jswe

Just show one question from randomized group, hide the others 4 years 1 month ago #78701

  • mr2jswe
  • mr2jswe's Avatar
  • Offline
  • Junior Lime
  • Posts: 22
  • Karma: 0
Thank you, I have run your survey, reproduced it to my needs, and it works flawlessly all the way into the back-end database tables. Ive checked and double-checked.

It is now a coherent solution.

Again, thanks for your time and effort. I hope this will be of use to others as well. Cheers.

Johnny
The administrator has disabled public write access.

Just show one question from randomized group, hide the others 4 years 1 month ago #78720

  • Mazi
  • Mazi's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5964
  • Thank you received: 363
  • Karma: 259
Thanks for your solution and its documentation, Tom.

Johnny, please open a ticket at the Bugtracker for the issues you noticed using my solution. It is weird that the result is not stored, this sounds like a bug.

Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)limesurvey.org'"
The administrator has disabled public write access.

Just show one question from randomized group, hide the others 4 years 1 month ago #78722

  • mr2jswe
  • mr2jswe's Avatar
  • Offline
  • Junior Lime
  • Posts: 22
  • Karma: 0
I have reported it to the Bugtracker just now. /J
The administrator has disabled public write access.

Just show one question from randomized group, hide the others 4 years 1 month ago #78747

  • Mazi
  • Mazi's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5964
  • Thank you received: 363
  • Karma: 259
mr2jswe wrote:
I have reported it to the Bugtracker just now. /J
Link?

Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)limesurvey.org'"
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Moderators: ITEd
Time to create page: 0.264 seconds