Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: random and rotating tesimonials

  1. #1
    Join Date
    Oct 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default random and rotating tesimonials

    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


    Code:
    /************************************ 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);
    Last edited by jscheuer1; 10-02-2012 at 03:18 PM. Reason: Format

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,926
    Thanks
    43
    Thanked 3,190 Times in 3,154 Posts
    Blog Entries
    12

    Default

    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:

    Code:
    /************************************ 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 . . .
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Oct 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    This will work great, thank you. There are closer to 12 quotes, but I didn't want to list them all on this thread.


    Quote Originally Posted by jscheuer1 View Post
    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:

    Code:
    /************************************ 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 . . .

  4. #4
    Join Date
    Oct 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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.

  5. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,926
    Thanks
    43
    Thanked 3,190 Times in 3,154 Posts
    Blog Entries
    12

    Default

    It shouldn't do that with this. Have you tried it out? I may have made a syntax error.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,926
    Thanks
    43
    Thanked 3,190 Times in 3,154 Posts
    Blog Entries
    12

    Default

    Well, I tried it out. With only 3 quotes, it starts at the beginning a lot, but not always:

    Code:
    <!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>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  7. #7
    Join Date
    Oct 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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

  8. #8
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,926
    Thanks
    43
    Thanked 3,190 Times in 3,154 Posts
    Blog Entries
    12

    Default

    The script on the server doesn't include the randomizing code I gave you:

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

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  9. #9
    Join Date
    Oct 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Not sure why it didn't load before, but I got it in there and works great - thank you!

  10. #10
    Join Date
    Oct 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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!!

Similar Threads

  1. Removing Random property from rotating banner
    By mavericks18 in forum Dynamic Drive scripts help
    Replies: 1
    Last Post: 11-13-2011, 12:22 AM
  2. Random rotating images (not slideshow/gallery)
    By spellbinder in forum Looking for such a script or service
    Replies: 9
    Last Post: 02-01-2010, 08:28 AM
  3. Random Content Order script not so random?
    By robins in forum Dynamic Drive scripts help
    Replies: 3
    Last Post: 04-03-2009, 01:37 PM
  4. rotating random link
    By JimmyHumbled in forum PHP
    Replies: 3
    Last Post: 10-22-2008, 12:27 AM
  5. Rotating .swf files at random with JavaScript?
    By visionsic in forum JavaScript
    Replies: 0
    Last Post: 05-18-2005, 06:42 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •