hi jscheuer1, thx for your quick reply,
the codes have to be chosen from a predefined list
if the codes run out, a message would appear" sorry no more codes left"
cumulative visitors.
the javascript code is actually yours I found it in this website and it worked,
I just want the codes to change instead of the names and upon refresh
I found this code in another website, it worked but it repeats:
Code:
<span id="randomText"></span>
<script>
// self instancing fucntion to isolate scope
(function(d) {
// handy helper functions first
function cookieGet(name) {
var reg = new RegExp('(?:^|; )' + encodeURIComponent(name) + '=([^;]*)').exec(d.cookie);
return reg ? reg[1] : null;
}
// use the DOM instead of innerHTML to avoid a reparse
function nodeAdd(e, newNode) {
e.appendChild(
typeof newNode == 'object' ? newNode : d.createTextNode(newNode)
);
}
function nodeFlush(e) {
while (e.firstChild) e.removeChild(e.firstChild);
}
function nodeReplace(e, newNode) {
nodeFlush(e);
nodeAdd(e, newNode);
}
// then our actual functionality
var
textList = [
"All the leaves are brown,",
"and the sky is grey.",
"I've been for a walk,",
"on a winter's day.",
"I'd be safe and warm,",
"If I was in L.A.",
"California dreaming,",
"On such a winter's day."
],
expires = 'Sat, 6 Jun 3057 22:32:00 -04:00', // RIP Myndo Waterly
current = cookieGet('currentRandomText');
current =
current == null ?
Math.floor(Math.random() * textList.length) :
Number(current);
nodeReplace(d.getElementById('randomText'), textList[current]);
d.cookie = 'currentRandomText=' + (
(current + 1) % textList.length
) + '; expires=' + expires;
})(document);
</script>
how can you fix it so the first sentence don't repeat and instead a "sorry, no more codes available" show up
thanks
Bookmarks