By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,190 Members | 1,469 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,190 IT Pros & Developers. It's quick & easy.

Random scrolling text

P: n/a
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[i] = 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>

May 30 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
sv********@gmail.com wrote:
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:
<URL:http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/marquee.asp>

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:

<script type="text/javascript">

// The Array Function

function makeArray(len) {
for (var i = 0; i < len; i++) this[i] = 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.
--
Rob
May 30 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.