473,399 Members | 3,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Random scrolling text

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
1 4243
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Midas NDT Sales | last post by:
I have been looking at a simple example of a scrolling text box (the one in the SAM book) as below: <script language="JavaScript"> var pos=100; function Scroll() { if...
44
by: Jim M | last post by:
I have had great success with using <iframe> with overflow-y set to auto. I can get a similar look with the <iframe> tag. BUT... In all cases I need to have fixed heights. Is there a way to...
1
by: Wesman | last post by:
Threads, textboxes and scrolling Thanks in advance for any information on this matter. I have run into a small richtextbox, scrolling and tread issue. Which has me totally confused. Instead of...
5
by: Will Gillen | last post by:
I need to have a "scrolling" text label or textbox at the bottom of my window to show the URL of where a song is being played from. I want the text to scroll on a single line from left to right in...
2
by: P2P | last post by:
Hi I am wondering if someone know of a free cross-browsers vertical scrolling script that - is cross cross-browsers - will call the scrolling content from an external html page or from a...
4
by: Keith Bentrup | last post by:
Hi all, I wrote a simple search function to find text in a textarea where not all the text is visible (ie. the text box displays 10 lines but there may be more than 1000 lines to search). I can...
4
by: tshad | last post by:
I am trying to set up an Image authorization where you type in the value that is in a picture to log on to our site. I found a program that is supposed to do it, but it doesn't seem to work. ...
5
by: PythonistL | last post by:
I am a newbie with Javascript. I have this simple script for scrolling text <HTML> <HEAD> <TITLE>Scrolling Message Script</TITLE> <SCRIPT language="JavaScript"><!-- var msg = 'My scrolling...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.