- Posts: 64
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Random pictures only shown once
- Andrea01
- Topic Author
- Offline
- Senior Member
Less
More
10 years 9 months ago #98701
by Andrea01
Random pictures only shown once was created by Andrea01
Hi,
I use below script from limesurvey workaroungs to Display Pictures in random order:
Is there a possibility to remove the shown picture and to present in the next group the remaining 3 pcitures?
<script>
$(document).ready(
function(){
// Find a random number (here between 1 and 4)
var randNumber = Math.floor(Math.random()*4 + 1);
// Save the number as answer of this question
$('input#answerSSSSSXGGXQQ').val(randNumber);
// Hide this answer field
document.getElementById("answerSSSSSXGGXQQ").style.display='none';
// Show the picture
picString = '<img src="pic/' + String(randNumber) + '.jpg">';
document.getElementById('pic').innerHTML = picString;
}
);</script>
Thanks in advance.
Andrea
I use below script from limesurvey workaroungs to Display Pictures in random order:
Is there a possibility to remove the shown picture and to present in the next group the remaining 3 pcitures?
<script>
$(document).ready(
function(){
// Find a random number (here between 1 and 4)
var randNumber = Math.floor(Math.random()*4 + 1);
// Save the number as answer of this question
$('input#answerSSSSSXGGXQQ').val(randNumber);
// Hide this answer field
document.getElementById("answerSSSSSXGGXQQ").style.display='none';
// Show the picture
picString = '<img src="pic/' + String(randNumber) + '.jpg">';
document.getElementById('pic').innerHTML = picString;
}
);</script>
Thanks in advance.
Andrea
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10114
- Thank you received: 3595
10 years 9 months ago - 10 years 9 months ago #98719
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Random pictures only shown once
Try something like this:
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function(){ // Retrieve the random number var randNumber = '{INSERTANS:SSSSSXGGXQQ}'; // Load the images $('#pic').html('<img src="pic1.jpg"><img src="pic2.jpg"><img src="pic3.jpg"><img src="pic4.jpg">'); //Remove the previously shown image $('#pic img[src="pic'+randNumber+'"]').remove(); }); </script>
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 10 years 9 months ago by tpartner.
The topic has been locked.
- Andrea01
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 64
- Thank you received: 0
10 years 9 months ago #98730
by Andrea01
Replied by Andrea01 on topic Random pictures only shown once
I put the code in a short text question, however, it still shows the Picture twice.
Any idea?
Any idea?
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10114
- Thank you received: 3595
10 years 9 months ago #98736
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Random pictures only shown once
Can you activate a test survey?
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- Andrea01
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 64
- Thank you received: 0
10 years 9 months ago #98737
by Andrea01
Replied by Andrea01 on topic Random pictures only shown once
Here it is
www.6ws.at/umfrage/index.php/527471/lang-de
Thanks
Andrea
www.6ws.at/umfrage/index.php/527471/lang-de
Thanks
Andrea
Attachment limesurvey_survey_527471.lss not found
Attachments:
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10114
- Thank you received: 3595
10 years 9 months ago #98738
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Random pictures only shown once
Okay, now I'm confused about what you are trying to do.
All I see is 3 questions, all of which are set to display a random image. I don't see one question to display a random image followed by another question to display "the remaining 3 pcitures".
I also don't see my code anywhere.
All I see is 3 questions, all of which are set to display a random image. I don't see one question to display a random image followed by another question to display "the remaining 3 pcitures".
I also don't see my code anywhere.
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- Andrea01
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 64
- Thank you received: 0
10 years 8 months ago #98828
by Andrea01
Replied by Andrea01 on topic Random pictures only shown once
Hi tpartner,
I put your code in a short text question and set it to hide (question 2 and 4).
No I cancled the hidden question and put your code into question 2 and 3.
Still doesn't work.
I put your code in a short text question and set it to hide (question 2 and 4).
No I cancled the hidden question and put your code into question 2 and 3.
Still doesn't work.
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10114
- Thank you received: 3595
10 years 8 months ago #98873
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Random pictures only shown once
Now, in questions 2 and 3, I see that you have BOTH the code to display "the remaining 3 pictures" AND the code to display a random image. You need to use one code snippet or the other.
Additionally, the images don't seem to be available (broken paths).
Additionally, the images don't seem to be available (broken paths).
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- CatherineA
- Offline
- New Member
Less
More
- Posts: 3
- Thank you received: 0
9 years 10 months ago #109739
by CatherineA
Replied by CatherineA on topic Random pictures only shown once
Hi !
I want to do exacly the same thing than what is shown there, and I get that I have to put the first code in the first question so that one image is picked up randomly. For the questions coming afterwards, I should put code that tpartner send.
I have two questions: how can I make it if i have 24 different images? Because, this line (
$('#pic img[src="pic'+randNumber+'"]').remove()
only remembers the last image presented right? what about for example the 12 already presented?
Plus, I plan on randomizing the questions within the groupquestion, so will it work anyway even if the questions are presented in a different order?
In advance, thanks for your help!
Catherine
I want to do exacly the same thing than what is shown there, and I get that I have to put the first code in the first question so that one image is picked up randomly. For the questions coming afterwards, I should put code that tpartner send.
I have two questions: how can I make it if i have 24 different images? Because, this line (
$('#pic img[src="pic'+randNumber+'"]').remove()
only remembers the last image presented right? what about for example the 12 already presented?
Plus, I plan on randomizing the questions within the groupquestion, so will it work anyway even if the questions are presented in a different order?
In advance, thanks for your help!
Catherine
The topic has been locked.