Not random text quotes

P

poeschlm

I am looking for some help in creating a script that will allow me to
define an array and then display those array elements in sequence on
page refresh. I can find as many random text scripts but I would like
one that will go in order of my array. I appreciate any help.

Mike
 
L

Lee

(e-mail address removed) said:
I am looking for some help in creating a script that will allow me to
define an array and then display those array elements in sequence on
page refresh. I can find as many random text scripts but I would like
one that will go in order of my array. I appreciate any help.

Learn about cookies.
If there is no cookie (first visit or cookies disabled), show a
random element. Otherwise, read the position in the array from
the cookie.
 
R

RobB

I am looking for some help in creating a script that will allow me to
define an array and then display those array elements in sequence on
page refresh. I can find as many random text scripts but I would like
one that will go in order of my array. I appreciate any help.

Mike

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>untitled</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<style type="text/css">

#Q {
width: 400px;
font: bold 16px times;
text-transform: capitalize;
text-align: center;
border-top: 3px #000 double;
border-bottom: 3px #000 double;
}

</style>
</head>
<body>
<div id="Q"></div>
<script type="text/javascript">

var quotes = [
'Lorem quotem 1 ipsum quotem 1 dolor quotem 1' ,
'Lorem quotem 2 ipsum quotem 2 dolor quotem 2' ,
'Lorem quotem 3 ipsum quotem 3 dolor quotem 3' ,
'Lorem quotem 4 ipsum quotem 4 dolor quotem 4' ,
'Lorem quotem 5 ipsum quotem 5 dolor quotem 5'
];

var idx_arr, idx_str, el;
if (!/__NOT_RANDOM_TEXT_QUOTES__/.test(top.name))
{
idx_arr = [];
for (var i = 0; i < quotes.length; ++i)
idx_arr.push(i);
idx_str = idx_arr.join(',');
}
else idx_str = top.name.split('__NOT_RANDOM_TEXT_QUOTES__')[1];
idx_arr = idx_str.split(',');
var first_idx = idx_arr.splice(0, 1);
if (el = document.getElementById('Q'))
{
while (el.hasChildNodes())
el.removeChild(el.lastChild);
el.appendChild(document.createTextNode(quotes[first_idx]));
}
idx_arr.push(first_idx);
idx_str = idx_arr.join(',');
top.name = '__NOT_RANDOM_TEXT_QUOTES__' + idx_str;
</script>
</body>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top