<HTML><HEAD>
<!--
-----------------
Multiple Messages
-----------------
-->
<SCRIPT LANGUAGE="JavaScript"><!-- hide from old browsers
/*
THE JAVASCRIPT COOKBOOK by Erica Sadun, webrx@mindspring.com
Copyright (c)1998 by Charles River Media. All Rights Reserved.
This applet can only be re-used or modifed by license holders of the
JavaScript Cookbook CD-ROM. Credit must be given in the source
code and this copyright notice must be maintained. If you do
not hold a license to the JavaScript Cookbook, you may NOT
duplicate or modify this code for your own use.
Use at your own risk. No warranty is given or implied of the suitability
of this applet for any specific application. Neither Erica Sadun nor
Charles River Media will be held responsible for any unwanted effects
due to the use of this applet or any derivative.
*/
// populate the message array
function createMsgs()
{
this[0] = "YOUR MESSAGE #1"
this[1] = "YOUR MESSAGE #2"
this[2] = "YOUR MESSAGE #3"
this[3] = "YOUR MESSAGE #4"
this[4] = "YOUR MESSAGE #5"
return this
}
var msgs=createMsgs()
var msgcounter = 0
var ticks = 0
var MSGS = 5
// Change the message if we've "ticked" out
function setMessage()
{
// redraw the current status
window.status = msgs[msgcounter]
// tick. See if it is time to change the message
ticks++
if (ticks == 10)
{
msgcounter = (msgcounter + 1) % MSGS
ticks = 0
}
// set the next time out
JSCTimeOutID = window.setTimeout('setMessage()',500)
}
<!-- done hiding --></SCRIPT></HEAD>
<BODY bgcolor="ffffff" link="0000ff" vlink="770077"
onload="JSCTimeOutID = window.setTimeout('setMessage()',500);">
<FONT COLOR="007777"><H1><IMG SRC="../GRAFX/UTENS.JPG" WIDTH=80 HEIGHT=50
ALIGN = LEFT>Marquee #7: Multiple Messages</H1></FONT>
<BLOCKQUOTE><FONT COLOR="770000">
This script loads changing messages at three second intervals.
</FONT></BLOCKQUOTE>
<FONT COLOR="007777"><H2>Discussion</H2></FONT>
<FONT SIZE=4>
The <FONT COLOR="770000">createMsgs()</FONT> populates the
msgs array. The <FONT COLOR="770000">msgcounter</FONT>
keeps track of the current message--it uses modulus to
flip back to zero when it reaches the maximum count.
Here, five seconds is created by "ticking" the watch
ten times over half second intervals because on some platforms,
the status line resets at mouse moves.
</FONT>
<PRE><FONT COLOR="770000">
// populate the message array
function createMsgs()
{
this[0] = "YOUR MESSAGE #1"
this[1] = "YOUR MESSAGE #2"
this[2] = "YOUR MESSAGE #3"
this[3] = "YOUR MESSAGE #4"
this[4] = "YOUR MESSAGE #5"
return this
}
var msgs=createMsgs()
var msgcounter = 0
var ticks = 0
var MSGS = 5
// Change the message if we've "ticked" out
function setMessage()
{
// redraw the current status
window.status = msgs[msgcounter]
// tick. See if it is time to change the message
ticks++
if (ticks == 10)
{
msgcounter = (msgcounter + 1) % MSGS
ticks = 0
}
// set the next time out
JSCTimeOutID = window.setTimeout('setMessage()',500)
}
</FONT></PRE>
<h5>Copyright ©1996 by Charles River Media, All Rights Reserved</h5>
</BODY>
</HTML>