[thelist] Re: Javascript: randomizing persistent text rotator

Chris Blessing webguy at mail.rit.edu
Mon Mar 25 08:31:10 CST 2002


Timothy-

I checked over your code and it seems to be working just fine for me.  I did
do some indentation clean-up for you (smirk) but aside from that, I just
took out the addition operands (++) from your txtStr[i++] references and
threw the rand code in there.

You may want to code something to keep track of the last number generated,
and then check that number to make sure you don't re-generate 2 "random"
numbers in a row (it currently does that quite a bit, looks like it's
pausing randomly).

Take a look (mind the wrap):

<!--
var Speed = 500;
var txtStr = new Array("1","2","3","4","5","6","7");
var i = 0;

if (document.layers) {
	document.write('<ilayer id="NN4"><layer id="NN4" height=25
width=100%><\/layer><\/ilayer>')
	var temp =
'document.NN4.document.NN42.document.write(txtStr[i]);'+'document.NN4.docume
nt.NN42.document.close()';
}
else if (document.getElementById) {
	document.write('<div id="message" style="position:relative;">...<\/div>');
	var temp = 'document.getElementById("message").firstChild.nodeValue =
txtStr[i];';
}
else if (document.all) {
	document.write('<div id="message" style="position:relative;">...<\/div>');
	var temp = 'message.innerHTML = txtStr[i];';
}

function rotateR() {
	i = Math.floor(Math.random()*txtStr.length)
	eval(temp);
	// removed the following...
	//if (i == txtStr.length) i = 0;
	setTimeout("rotateR()", Speed);
}

window.onload = rotateR;
-->


Chris Blessing
webguy at mail.rit.edu
http://www.330i.net

> -----Original Message-----
> From: thelist-admin at lists.evolt.org
> [mailto:thelist-admin at lists.evolt.org]On Behalf Of Timothy Martens
> Sent: Monday, March 25, 2002 3:54 AM
> To: thelist at lists.evolt.org
> Subject: [thelist] Re: Javascript: randomizing persistent text rotator
>
>
> Here's a current working example
>
> http://home.hawaii.rr.com/timfm/theList/rotator.html
>
> Rudy wrote:
>
> >don't you have to declare temp as a var?
> >so that it can be known inside the rotateR function?
>
> Yes I guess it's good form to say "var temp =" but "temp =" works as
> well.
>
> >file://t
> >i know that's not your sig, but that's
> >what is shows in outlook express)
>
> Hmmm - I usually just sign stuff with "//t"
> So outlook is throwing a "file:" in front of it. I wonder if that
> happens with other mail clients?
>
> ::::::::::::::::::::::::
> <!--Timothy Martens
> timfm at hawaii.rr.com-->
>
> --
> For unsubscribe and other options, including
> the Tip Harvester and archive of thelist go to:
> http://lists.evolt.org Workers of the Web, evolt !




More information about the thelist mailing list