Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8456979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:41:19+00:00 2026-06-10T12:41:19+00:00

I have a website that uses javascript to randomly display a list of quotes.

  • 0

I have a website that uses javascript to randomly display a list of quotes. I’ve used this same script across 7-8 other sites without issue, but on this current site it just crashes the browser after a few seconds.

I did have a similar problem which was due to the javascript being called on pages that didn’t feature quotes, but I fixed this by moving the javascript into the same ‘includes’ file as the quotes (meaning one can never be called without the other)

The site is on the same server space as the other and the files are exactly the same, so I can’t work out why this site is having a problem and the others aren’t…

Here is the script…

<ul id="quote">
<?php perch_content('Testimonials'); ?>
</ul>

<script type="text/javascript"> 

this.randomtip = function() {
    var pause = 5000; // define the pause for each tip (in milliseconds) Feel free to make the pause longer so users can have time to read the tips :)
    var length = $("#quote li").length;
    var temp = -1;
    this.getRan = function() {
        // get the random number
        var ran = Math.floor(Math.random() * length) + 1;
        return ran;
    };
    this.show = function() {
        var ran = getRan();
        // to avoid repeating tips we need to check 
        while (ran == temp) {
            ran = getRan();
        };
        temp = ran;
        $("#quote li").hide();
        $("#quote li:nth-child(" + ran + ")").fadeIn(500);
    };
    // initiate the script and also set an interval
    show();
    setInterval(show, pause);
};
$(document).ready(function() {
    randomtip();
});
</script> 

Thanks in advance guys!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T12:41:21+00:00Added an answer on June 10, 2026 at 12:41 pm

    You only have one quote, which means that getRan() is always going to return the same value (1). Since temp is set to the previous value, you get an endless loop here:

    var ran = getRan();
    while (ran == temp) {
        ran = getRan();
    }
    

    If you wrap it in a safety-check like this, it should work.

    var ran = getRan();
    if (length > 1) {
        while (ran == temp) {
            ran = getRan();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a website that uses the JavaScript SDK, and I have a facebook
I have a website that is mainly based on JavaScript. It uses a REST
So I have this ASP.Net 2.0 website that uses functions contained within a JS
I have a website that uses some JavaScript APIs to create flash-based charts (namely
I have a website that is 1 html file and uses javascript to hide
We have a website that uses javascript, prototype for client scripting, We are starting
I have a main web-site that uses passive federation (ADFS 2.0) This website has
I hope someone can help me. I have a website that uses javascript to
i have a website that uses a number of containers (div's). In this scenario,
I have a website that uses JSP as its view technology (and Spring MVC

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.