Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jun 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Random quote generator to Sequential

    The script below currently displays each of the "quotations" randomly and I would like it to display them in order. If somebody could show me what needs to be changed to make that happen I'd very much appreciate it.

    [CODE]
    <SCRIPT type="text/javascript">
    var quotations = new Array()
    quotations[0]= "<b>Quote 0</b>"
    quotations[1]= "<b>Quote 1</b>"
    quotations[2]= "<b>Quote 2</b>"
    quotations[3]= "<b>Quote 3</b>"
    quotations[4]= "<b>Quote 4</b>"
    quotations[5]= "<b>Quote 5</b>"
    quotations[6]= "<b>Quote 6</b>"
    quotations[7]= "<b>Quote 7</b>"
    quotations[8]= "<b>Quote 8</b>"
    quotations[9]= "<b>Quote 9</b>"
    quotations[10]= "<b>Quote 10</b>"
    function display()
    {
    a=Math.floor(Math.random()*quotations.length)
    document.getElementById('quotation').innerHTML=quotations[a]
    setTimeout("display()",5000)
    }
    </SCRIPT>
    [CODE]

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,898
    Thanks
    203
    Thanked 2,530 Times in 2,508 Posts
    Here you are:-

    Code:
    <html> 
    <head> 
    <body onload = "display()">
    
    <div id = "quotation"></div>
    
    <script type="text/javascript">
    
    var quotations = [];
    quotations[0]= "<b>Quote 0</b>"
    quotations[1]= "<b>Quote 1</b>"
    quotations[2]= "<b>Quote 2</b>"
    quotations[3]= "<b>Quote 3</b>"
    quotations[4]= "<b>Quote 4</b>"
    quotations[5]= "<b>Quote 5</b>"
    quotations[6]= "<b>Quote 6</b>"
    quotations[7]= "<b>Quote 7</b>"
    quotations[8]= "<b>Quote 8</b>"
    quotations[9]= "<b>Quote 9</b>"
    quotations[10]= "<b>Quote 10</b>"
    
    var index = 0;
    function display() {
    document.getElementById('quotation').innerHTML=quotations[index];
    index++;
    if (index >10) {index = 0}
    setTimeout(display,5000);
    }
    
    </script>
    
    
    </body>
    </html>
    The <b> and </b> bold tags are deprecated and obsolete. Style your display using CSS.

    "In the beginner's mind there are many possibilities, but in the expert's mind there are few” - Shunryu Suzuki (Japanese Zen priest, ?-1971)
    Last edited by Philip M; 06-26-2012 at 07:01 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    New to the CF scene
    Join Date
    Jun 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks! Worked perfectly!


  •  

    Posting Permissions

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