Entry
How do I load variables from a file on the server?
Mar 31st, 2000 10:05
Eddie Shipman, http://wsabstract.com/javatutors/matrixscroll/
I am using the "Dot-Matrix" scroller by Ray M from
http://wsabstract.com/javatutors/matrixscroll/ on a web page for a
baseball league and want to show the latest scores. But I didn't
want to have to update the entire home page every time I wanted to
change scores. How'd I do it? I placed the scores in a separate
file and called it like this:
*** Here's my scores.js:
var data = "Mets 6-Braves 2 Rangers 5-Devil Rays 2"
*** Here's my HTML file:
<html>
<head>
<title>Latest Scores</title>
<!--
The next line loads the variable "data" with the
string I want to use in the scrolling display
-->
<script src="scores.js" language="javascript"></script>
<script language="javascript">
/*
Dot Matrix Scroller - by RayM 06-01-00
For tutorial and full source to script, see
http://wsabstract.com/javatutors/matrixscroll/
*/
//specify the directory where the images are in,
//or leave blank if they are in the same directory as this script.
//For example, "images/" or "" are both valid values
var imagepath=""
// text string to display loaded from
// scores.js
var text=data
// number of display cells
var nc=8;
// scroll speed in msec (default=130)
var spd=130;
// counter for one whole loop (offset loop)
var count=0;
// starting pos of substring
var offs=0;
//preload images routine (By Wsabstract.com)
var preloadimages=new Array()
for (p=32;p<=163;p++){
preloadimages[p]=new Image()
preloadimages[p].src=imagepath+"sm"+p+".gif"
}
// update scrolling display every 130 msec
function startscroll() {
action=window.setInterval("go()",spd);
}
// main loop. done every 130 msec
function go() {
// get substring
strd=text.substr(offs,(count+1));
// no longer than 21 chars (no. of cells)
var str=strd.substr(0,nc);
// if text has reached left side, start chopping off
if (count>(nc-2) && str.length<nc) {
// how many spaces to add at end, if any
var se=(nc-len);
while (str.length<nc) {
// pad out end with spaces
str=str+" ";
se+=1;
}
}
// get length of substring
len=str.length;
// counter for display characters sub-loop
var c=0;
// do for all characters in this substring
while (c<len) {
// select a single char from this sub-string
r=str.substr(c,1);
// get ascii code of this char
g=r.charCodeAt(0);
chr=eval('document.c'+((nc+1)-len+c));
// display picture
chr.src=imagepath+"sm"+g+".gif";
// inc char counter
c+=1;
}
// inc this when done one whole loop
count+=1;
if (count>=nc) {
offs+=1;
}
// wrap at end
if (count>(text.length+(nc-1))) {
count=0;
offs=0;
}
}
</script>
</head>
<body onload="startscroll()">
<table cols="8" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<img src="sm32.gif" width="16" height="22" name="c1">
</td>
<td>
<img src="sm32.gif" width="16" height="22" name="c2">
</td>
<td>
<img src="sm32.gif" width="16" height="22" name="c3">
</td>
<td>
<img src="sm32.gif" width="16" height="22" name="c4">
</td>
<td>
<img src="sm32.gif" width="16" height="22" name="c5">
</td>
<td>
<img src="sm32.gif" width="16" height="22" name="c6">
</td>
<td>
<img src="sm32.gif" width="16" height="22" name="c7">
</td>
<td>
<img src="sm32.gif" width="16" height="22" name="c8">
</td>
</tr>
</table>
</body>
</html>