Random scrolling text

S

sven.daems

Hy

I want to add a sort of news service to my site. I've a number of
messages, wich I want to be shown in a <marquee> tag. I've found a
simple scrit that generates an random message (wich I've putted in an
array) and the message is shown in an marquee tag. The problem is that
for changing the message, a reload of the page is required. Isn't
there a way to reload the message? Or every time the marquee tag shows
a message, it will be a differrent message? Or perhaps not using the
marquee tag, but another way to scroll text trough a page?

Thanxs in advance
Sven Daems

<SCRIPT LANGUAGE = "JavaScript">

// The Array Function

function makeArray(len) {
for (var i = 0; i < len; i++) this = null;
this.length = len;
}

// This is where the array of text/images/sounds is created.

ideas = new makeArray(22);
ideas[0] = "Message1"
.....
ideas[21] = "Message22"


// The random number generator.

function rand(n) {
seed = (0x015a4e35 * seed) % 0x7fffffff;
return (seed >> 16) % n;
}

var now = new Date()
var seed = now.getTime() % 0xffffffff

</SCRIPT>
</head>
--------------------------------------------
<body background="images/midden_top.jpg">
<marquee>
<SCRIPT LANGUAGE = "JavaScript">

// Where you place this is where the random object will be displayed.

document.write(ideas[rand(ideas.length)])

</SCRIPT>
</marquee>
 
R

RobG

Hy

I want to add a sort of news service to my site. I've a number of
messages, wich I want to be shown in a <marquee> tag. I've found a

The marquee element is not part of the W3C HTML 4 specification, it is
supported in varying degrees by many browsers but it is likely that
there are some that don't support it at all.

MozDev:
<URL:http://developer.mozilla.org/en/docs/HTML:Element:marquee>

MSDN:
simple scrit that generates an random message (wich I've putted in an
array) and the message is shown in an marquee tag. The problem is that
for changing the message, a reload of the page is required. Isn't
there a way to reload the message? Or every time the marquee tag shows
a message, it will be a differrent message? Or perhaps not using the
marquee tag, but another way to scroll text trough a page?

The link above will tell you most of that, but again, support is likely
to be patchy.

<SCRIPT LANGUAGE = "JavaScript">

The language attribute is deprecated, type is required:

// The Array Function

function makeArray(len) {
for (var i = 0; i < len; i++) this = null;
this.length = len;
}


That is a totally useless function. Use the in-built JavaScript array
object.
// This is where the array of text/images/sounds is created.

ideas = new makeArray(22);
ideas[0] = "Message1"
.....
ideas[21] = "Message22"

Seems much easier to use:

ideas = [
"Message 1",
"Message 2",
"Message 3",
...
"Message n"
];

// The random number generator.

function rand(n) {
seed = (0x015a4e35 * seed) % 0x7fffffff;
return (seed >> 16) % n;
}

Why not use Math.random? For this exercise, it doesn't seem that a
separate random number function is required anyway. A 'get next random
message' function might look something like:

function getRandMsg(msgArray){
var rn = Math.random()*msgArray.length | 0;
return msgArray[rn];
}


[...]
document.write(ideas[rand(ideas.length)])

Calling document.write after the page is loaded will clear the entire
page before writing new content. Use DOM or innerHTML to write new
content for the element.

Search the archives for scrolling banners that don't use a marquee
element. I find them very annoying, they are little used - I suspect
many others find them annoying too.
 

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,774
Messages
2,569,599
Members
45,173
Latest member
GeraldReund
Top