...

View Full Version : Random quote generator to Sequential



JaredRay991
06-26-2012, 07:12 PM
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]

Philip M
06-26-2012, 07:58 PM
Here you are:-


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

JaredRay991
06-27-2012, 05:33 PM
Thanks! Worked perfectly!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum