Welcome to the LimeSurvey Community Forum

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

Pick a random name out of a list

  • andreasklinar
  • andreasklinar's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 6 months ago #206266 by andreasklinar
Pick a random name out of a list was created by andreasklinar
Hi,

i am quite new to LimeSurvey and i am just doing my first survey here as a part for my bachelor degree.

In a text of one question I want a name to be randomly selected from a list.

How do I do this? I tried to figure it out but could not find any information.
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 6 months ago #206269 by holch
Replied by holch on topic Pick a random name out of a list
Can you explain a little bit more what you are trying to do? Because picking a name from a list is not a feature that Limesurvey has out of the box, but depending on what you are trying to actually do, there might be a fairly simple solution to this.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 6 months ago #206276 by tpartner
Replied by tpartner on topic Pick a random name out of a list
...and, do you need the random name stored in the data?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • andreasklinar
  • andreasklinar's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 6 months ago #206288 by andreasklinar
Replied by andreasklinar on topic Pick a random name out of a list
I have one "question", where i explain a fictitious agent and the name of this agent should be randomly generated from a pre-defined list.
There is no answer to this question, just a simple text.
The topic has been locked.
  • andreasklinar
  • andreasklinar's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 6 months ago #206289 by andreasklinar
Replied by andreasklinar on topic Pick a random name out of a list
No, the name does not need to be stored.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 6 months ago - 3 years 6 months ago #206320 by tpartner
Replied by tpartner on topic Pick a random name out of a list
Place something like this in the question source. It will load the <span> element with a random name from a list defined in the "names" array.

Code:
The random name is <span class="random-name">&amp;nbsp;</span>.
<script type="text/javascript" charset="utf-8">
    $(document).on('ready pjax:scriptcomplete',function(){
 
    // Define the names
    var names = ['Tom', 'Dick', 'Harry', 'Jane', 'Susan', 'Mary'];
 
    // Randomize the names
    shuffleArray(names);
 
    // Load the <span> element with the random name
    $('#question{QID} span.random-name').text(names[0]);
 
  });
 
  function shuffleArray(array) {
    for (var i = array.length - 1; i > 0; i--) {
      var j = Math.floor(Math.random() * (i + 1));
      var temp = array[i];
      array[i] = array[j];
      array[j] = temp;
    }
    return array;
  }  
</script>

Sample survey attached:

File Attachment:

File Name: limesurvey...5(1).lss
File Size:15 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 3 years 6 months ago by tpartner.
The topic has been locked.
  • andreasklinar
  • andreasklinar's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 6 months ago #206498 by andreasklinar
Replied by andreasklinar on topic Pick a random name out of a list
this works perfect - thanks a lot!!!
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose