Random pictures only shown once

More
3 years 7 months ago #98701 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

Please Log in to join the conversation.

More
3 years 7 months ago - 3 years 7 months ago #98719 by tpartner
Try something like this:

<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: 3 years 7 months ago by tpartner.

Please Log in to join the conversation.

More
3 years 7 months ago #98730 by Andrea01
I put the code in a short text question, however, it still shows the Picture twice.

Any idea?

Please Log in to join the conversation.

More
3 years 7 months ago #98736 by tpartner
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.

Please Log in to join the conversation.

More
3 years 7 months ago #98737 by Andrea01
Here it is

www.6ws.at/umfrage/index.php/527471/lang-de


Thanks
Andrea

Attachment limesurvey_survey_527471.lss not found

Attachments:

Please Log in to join the conversation.

More
3 years 7 months ago #98738 by tpartner
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.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

More
3 years 7 months ago #98828 by Andrea01
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.

Please Log in to join the conversation.

More
3 years 7 months ago #98873 by tpartner
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).

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

More
2 years 9 months ago #109739 by CatherineA
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

Please Log in to join the conversation.