Welcome, Guest
Username: Password: Remember me

TOPIC: Random pictures only shown once

Random pictures only shown once 1 year 1 month ago #98701

  • Andrea
  • Andrea's Avatar
  • OFFLINE
  • Gold Donor
  • Posts: 33
  • Karma: 0
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
The administrator has disabled public write access.

Random pictures only shown once 1 year 1 month ago #98719

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4206
  • Thank you received: 790
  • Karma: 360
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
Last Edit: 1 year 1 month ago by tpartner.
The administrator has disabled public write access.

Random pictures only shown once 1 year 1 month ago #98730

  • Andrea
  • Andrea's Avatar
  • OFFLINE
  • Gold Donor
  • Posts: 33
  • Karma: 0
I put the code in a short text question, however, it still shows the Picture twice.

Any idea?
The administrator has disabled public write access.

Random pictures only shown once 1 year 1 month ago #98736

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4206
  • Thank you received: 790
  • Karma: 360
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Random pictures only shown once 1 year 1 month ago #98737

  • Andrea
  • Andrea's Avatar
  • OFFLINE
  • Gold Donor
  • Posts: 33
  • Karma: 0
Here it is

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


Thanks
Andrea

Attachment limesurvey_survey_527471.lss not found

The administrator has disabled public write access.

Random pictures only shown once 1 year 1 month ago #98738

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4206
  • Thank you received: 790
  • Karma: 360
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Random pictures only shown once 1 year 1 month ago #98828

  • Andrea
  • Andrea's Avatar
  • OFFLINE
  • Gold Donor
  • Posts: 33
  • Karma: 0
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.
The administrator has disabled public write access.

Random pictures only shown once 1 year 1 month ago #98873

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4206
  • Thank you received: 790
  • Karma: 360
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Random pictures only shown once 3 months 3 weeks ago #109739

  • CatherineA
  • CatherineA's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 21
  • Karma: 0
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
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.145 seconds
Donation Image