Log in

View Full Version : random and rotating tesimonials



modedeco
10-02-2012, 02:50 PM
I got this script from a post that Coothead had written for someone else and it works great, but I also need the quotes to appear randomly, I have seen the scripts that can do this, but I am not sure how to add them so they will work, any help would be appreciated.

Thanks



/************************************ Editable values **************************************************/

var myquotes=[

'<p>&quot;Testimonial 1 </p>',

'<p>&quot;Testimonial 2</p>',

'<p>&quot;Testimonial 3</p>'

];

/* This rotates the quote every 20 seconds. Replace 20 with
(the number of seconds you want) * 1000 */

var delay=20*1000;
var rndm;

/************************************************************************************************************/

function rotatequote() {
thequote=myquotes.shift(); /* Pull the top one */
myquotes.push(thequote); /* And add it back to the end */

document.getElementById('quotetext').innerHTML=thequote;


setTimeout(function(){rotatequote()},delay);
}
window.addEventListener?
window.addEventListener('load',rotatequote,false):
window.attachEvent('onload',rotatequote);

jscheuer1
10-02-2012, 03:28 PM
With just three quotes, random each time would mean a lot of repeats. Even with a lot of quotes, you could get repeats. Often what's done is, while the page loads the quotes are shuffled once. After that they show in that shuffled order until the page is refreshed. Would that be acceptable?

If so, add the highlighted:


/************************************ Editable values **************************************************/

var myquotes=[

'<p>&quot;Testimonial 1 </p>',

'<p>&quot;Testimonial 2</p>',

'<p>&quot;Testimonial 3</p>'

].sort(function(){return 0.5 - Math.random();});

/* This rotates the quot . . .

modedeco
10-02-2012, 03:44 PM
This will work great, thank you. There are closer to 12 quotes, but I didn't want to list them all on this thread.



With just three quotes, random each time would mean a lot of repeats. Even with a lot of quotes, you could get repeats. Often what's done is, while the page loads the quotes are shuffled once. After that they show in that shuffled order until the page is refreshed. Would that be acceptable?

If so, add the highlighted:


/************************************ Editable values **************************************************/

var myquotes=[

'<p>&quot;Testimonial 1 </p>',

'<p>&quot;Testimonial 2</p>',

'<p>&quot;Testimonial 3</p>'

].sort(function(){return 0.5 - Math.random();});

/* This rotates the quot . . .

modedeco
10-02-2012, 03:53 PM
Actually the client has asked for the quotes to be on every page of the site, so when you go to a new page it is still reverting to the first quote so they never get past the first one. The completely random function might work better.

jscheuer1
10-02-2012, 03:58 PM
It shouldn't do that with this. Have you tried it out? I may have made a syntax error.

jscheuer1
10-02-2012, 04:05 PM
Well, I tried it out. With only 3 quotes, it starts at the beginning a lot, but not always:


<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript">
/************************************ Editable values **************************************************/

var myquotes=[

'<p>&quot;Testimonial 1 </p>',

'<p>&quot;Testimonial 2</p>',

'<p>&quot;Testimonial 3</p>'

].sort(function(){return 0.5 - Math.random()});

/* This rotates the quote every 20 seconds. Replace 20 with
(the number of seconds you want) * 1000 */

var delay=20*1000;
var rndm;

/************************************************************************************************************/

function rotatequote() {
thequote=myquotes.shift(); /* Pull the top one */
myquotes.push(thequote); /* And add it back to the end */

document.getElementById('quotetext').innerHTML=thequote;


setTimeout(function(){rotatequote()},delay);
}
window.addEventListener?
window.addEventListener('load',rotatequote,false):
window.attachEvent('onload',rotatequote);
</script>
</head>
<body>
<div id="quotetext"></div>
</body>
</html>

modedeco
10-02-2012, 05:36 PM
I put it into my test site, but haven't had any luck, any ideas?
Again, thanks for all your help.
http://modedesignco.com/ps/change/index.html

jscheuer1
10-02-2012, 07:18 PM
The script on the server doesn't include the randomizing code I gave you:

modedesignco.com/ps/change/scripts/rotating-quotes.js

modedeco
10-02-2012, 08:15 PM
Not sure why it didn't load before, but I got it in there and works great - thank you!

modedeco
10-12-2012, 07:18 PM
This script has worked great, but I just loaded it to the clients server at a different host and it isn't working, any ideas? All the files are uploaded, worked fine on my host, all the paths have not changed.

Thanks!!

jscheuer1
10-13-2012, 12:23 AM
Please include a link to the page that contains the problematic code so we can check it out.

SpeedSki
10-26-2013, 02:10 AM
thank you. works perfectly for me, see sample here http://www.vitimesharesales.com/Elkhorn-Village-Sun-Valley-Idaho.html