Welcome to the LimeSurvey Community Forum

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

Pipe random store name to a set of questions from a list of store name

  • saifshaikh
  • saifshaikh's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
8 months 4 weeks ago #245920 by saifshaikh
Please help us help you and fill where relevant:
Your LimeSurvey version: [2.73.3-1]
Own server or LimeSurvey hosting: hosted
Survey theme/template: default
==================
Hi,

I would like to pipe random store name to a set of questions from a list of stores

eg.
Q1 - Store List  (Hidden)
store 1
store 2
store 3
store 4
store 5

Q2 - Have you heard of {store 3}?

Thank you in advance,

Saif

Please Log in to join the conversation.

  • saifshaikh
  • saifshaikh's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
8 months 4 weeks ago #245921 by saifshaikh
I was able generate random name from the thread below, but was unable to pipe that into another question
forums.limesurvey.org/forum/can-i-do-thi...m-name-out-of-a-list

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 months 4 weeks ago - 8 months 4 weeks ago #245922 by Joffm
Hi,
did you import the sample survey?
So, what is your problem to show the randiom name?

I think you did not and missed to insert the <span> element.

Please show what you did!
lss export of this relevant question.


But you know that this solution does not store the selected name.
If you want to store the name, please tell us.
In this case the solution is nearly the same, but only nearly.

Joffm

 

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

Please Log in to join the conversation.

  • saifshaikh
  • saifshaikh's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
8 months 4 weeks ago #245924 by saifshaikh
 

File Attachment:

File Name: limesurvey...2533.lss
File Size:13 KB

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 months 4 weeks ago - 8 months 4 weeks ago #245925 by Joffm
Hi,
as I see you do not store the name.
Therefore you can't access anything by {q1.shown}
This you see easily when you activate the survey and enter some data.

Okay either you change the first quuestion to your desired type, like
 

or (if you want to store the name) use a first question of type "short text" in a different group which you hide by the css class "hidden"
Here you enter this javascript snippet
Code:
<script type="text/javascript" charset="utf-8">
    $(document).on('ready pjax:scriptcomplete',function(){
 
    // Define the names
    var names = ['Store 1', 'Store 2', 'Store 3', 'Store 4', 'Store 5', 'Store 6'];
 
    // Randomize the names
    shuffleArray(names);
 
    // Load the <input> element with the random name
    $('#question{QID} input[type="text"]').val(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>[/i][/i]
You see it is nearly the same, but you do not insert the selected store into the <span> element, but into the text.

And the result you can pupe into the next question
"Have you ever heard of {q1}?"

 


And the solution without javascript.
Generate a random number (1-5
{if(is_empty(randnum),rand(1,5),randnum)}

and display the store with a nested IF
{if(randnum==1,"Store 1",if(randnum==2,"Store 2",if(randnum==3,"Store 3",if(randnum==4,"Store 4","Store 5"))))}

Joffm

 

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

Please Log in to join the conversation.

  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 months 4 weeks ago #245926 by holch
First of all a couple of things:

Your LimeSurvey version: [2.73.3-1]


You really shouldn't run such an old and outdates version of Limesurvey in production. 2.73.x was released at the end of 2017 (I don't think a 2.73.3-1 has ever existed though) , so almost 6 years ago and is not supported anymore for quite while now. It hasn't received any updates, bug fixes, security patches for almost 6 years now.

Own server or LimeSurvey hosting: hosted


Given the age of your installation it is save to say that your installation is NOT hosted by Limesurvey GmbH but must be an own server of your company, institution, etc.

Of course I don't have such an ancient installation running to test it with 2.73.x but I have opened it with LS 3.x, which is the closest supported version to your outdated version (we are at LS 6.x right now).

I'll try to have a look at your LSS and see what might be wrong.

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

The following user(s) said Thank You: saifshaikh

Please Log in to join the conversation.

  • saifshaikh
  • saifshaikh's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
8 months 4 weeks ago #245946 by saifshaikh
Thank you for the solution, I will try out the above solution 

Please Log in to join the conversation.

  • saifshaikh
  • saifshaikh's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
8 months 3 weeks ago - 8 months 3 weeks ago #246243 by saifshaikh
Thanks Joffm, that worked as per my requirement.

I have duplicated the question Q-BE2, to generate additional random store name. is it possible that the same store name is not randomly selected as in Q-BE.
Both BE & BE2 should be unique.

I have attached sample survey.  

File Attachment:

File Name: limesurvey...8928.lss
File Size:29 KB


Thanks & advance 
Last edit: 8 months 3 weeks ago by saifshaikh.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 months 3 weeks ago #246244 by Joffm
1. Remove BE2
2. Change BE to "multiple short text" with two subquestions
3. Change this part of the script
Code:
    // Load the <input> element with the random name
    $('#question{QID} input[type="text"]:eq(0)').val(names[0]);
    $('#question{QID} input[type="text"]:eq(1)').val(names[1]);

that the first randomized brand is stored int the first subquestion, the second in the second.
 

And I advice to change these four "text display" questions to only one with a nested IF, as I showed before
Insted of this
{if(randnum==1,"Store 1",if(randnum==2,"Store 2",if(randnum=,"Store 3",if(randnum==4,"Store 4","Store 5"))))}
use this
{if(BE_SQ001=="Douglas","Douglas is a European beauty retail chain...",if(BE_SQ001="Ulta","Ulta: Ulta is a beauty retailer in the United States ...",if(...))))}

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

Lime-years ahead

Online-surveys for every purse and purpose