Dragonfish
Programmer
First thanks for all the help I´ve had up till now.
I´ve posted this already under the heading "Bad syntax with a scroller" but I´m only now beginning to understand the problem. The script I found in a book works - I´ve just tried it - but it means writing the script in the HTML file, which I really don´t want to do, I want to work with external .js files only and they obviously behave differently !!!
In the second script - the one I want to use - I hat trouble handing over the values and I solved the problem this way:
.
.
scrolling(scrollmessage,textlength,textwidth,pos);
}
function scrolling(scrollmessage,textlength,textwidth,pos) {
.
.
This seems to work until:
.
.
setTimeout("scrolling()", 100);
}
Which calls the function scrolling again this time apparently without the values (scrollmessage,textlength,textwidth,pos)
Changeing the line to:
setTimeout("scrolling(scrollmessage,textlength,textwidth,pos)", 100);
does´nt help either.
For those who don´t want to read further I´ll say thanks for any advice
DavidinGermany
Here´s the first script (which works) all in one HTML file
***************************************************************
<html>
<head>
<script language="JavaScript">
var scrollmessage=" *** Dies ist ein Testtext *** Dies ist ein 2 Testtext *** Dies ist ein 3 Testtext";
var textlength = scrollmessage.length;
var textwidth = 50;
var pos = -(textwidth + 2);
function scrolling() {
pos++;
var scroller = " ";
if (pos == textlength) {
pos = -(textwidth + 2);
}
if (pos < 0) {
for (var i = 1; i <= Math.abs(pos); i++) {
// Leerzeichen einfügen
scroller = scroller + " ";
}
scroller = scroller + scrollmessage.substring(0, textwidth - i + 1);
}
else {
scroller = scroller + scrollmessage.substring(pos, textwidth + pos);
}
window.status = scroller;
setTimeout("scrolling()", 100);
}
</script>
</head>
<body onLoad="scrolling()">
</body>
</html>
***************************************************************
Now here´s the script I want to use (without any JavaSript code in the HTML file)
<html>
<head>
<script language="JavaScript" src="main.js" type="text/javascript"></script>
</head>
<body onLoad="textscroller()">
</body>
</html>
***************************************************************
The .js file
function textscroller() {
var scrollmessage=" *** Dies ist ein Testtext *** Dies ist ein 2 Testtext *** Dies ist ein 3 Testtext";
var textlength = scrollmessage.length;
var textwidth = 50;
var pos = -(textwidth + 2);
scrolling(scrollmessage,textlength,textwidth,pos);
}
function scrolling(scrollmessage,textlength,textwidth,pos) {
pos++;
var scroller = " ";
if (pos == textlength) {
pos = -(textwidth + 2);
}
if (pos < 0) {
for (var i = 1; i <= Math.abs(pos); i++) {
// Leerzeichen einfügen
scroller = scroller + " ";
}
scroller = scroller + scrollmessage.substring(0, textwidth - i + 1);
}
else {
scroller = scroller + scrollmessage.substring(pos, textwidth + pos);
}
window.status = scroller;
setTimeout("scrolling()", 100);
}
I´ve posted this already under the heading "Bad syntax with a scroller" but I´m only now beginning to understand the problem. The script I found in a book works - I´ve just tried it - but it means writing the script in the HTML file, which I really don´t want to do, I want to work with external .js files only and they obviously behave differently !!!
In the second script - the one I want to use - I hat trouble handing over the values and I solved the problem this way:
.
.
scrolling(scrollmessage,textlength,textwidth,pos);
}
function scrolling(scrollmessage,textlength,textwidth,pos) {
.
.
This seems to work until:
.
.
setTimeout("scrolling()", 100);
}
Which calls the function scrolling again this time apparently without the values (scrollmessage,textlength,textwidth,pos)
Changeing the line to:
setTimeout("scrolling(scrollmessage,textlength,textwidth,pos)", 100);
does´nt help either.
For those who don´t want to read further I´ll say thanks for any advice
DavidinGermany
Here´s the first script (which works) all in one HTML file
***************************************************************
<html>
<head>
<script language="JavaScript">
var scrollmessage=" *** Dies ist ein Testtext *** Dies ist ein 2 Testtext *** Dies ist ein 3 Testtext";
var textlength = scrollmessage.length;
var textwidth = 50;
var pos = -(textwidth + 2);
function scrolling() {
pos++;
var scroller = " ";
if (pos == textlength) {
pos = -(textwidth + 2);
}
if (pos < 0) {
for (var i = 1; i <= Math.abs(pos); i++) {
// Leerzeichen einfügen
scroller = scroller + " ";
}
scroller = scroller + scrollmessage.substring(0, textwidth - i + 1);
}
else {
scroller = scroller + scrollmessage.substring(pos, textwidth + pos);
}
window.status = scroller;
setTimeout("scrolling()", 100);
}
</script>
</head>
<body onLoad="scrolling()">
</body>
</html>
***************************************************************
Now here´s the script I want to use (without any JavaSript code in the HTML file)
<html>
<head>
<script language="JavaScript" src="main.js" type="text/javascript"></script>
</head>
<body onLoad="textscroller()">
</body>
</html>
***************************************************************
The .js file
function textscroller() {
var scrollmessage=" *** Dies ist ein Testtext *** Dies ist ein 2 Testtext *** Dies ist ein 3 Testtext";
var textlength = scrollmessage.length;
var textwidth = 50;
var pos = -(textwidth + 2);
scrolling(scrollmessage,textlength,textwidth,pos);
}
function scrolling(scrollmessage,textlength,textwidth,pos) {
pos++;
var scroller = " ";
if (pos == textlength) {
pos = -(textwidth + 2);
}
if (pos < 0) {
for (var i = 1; i <= Math.abs(pos); i++) {
// Leerzeichen einfügen
scroller = scroller + " ";
}
scroller = scroller + scrollmessage.substring(0, textwidth - i + 1);
}
else {
scroller = scroller + scrollmessage.substring(pos, textwidth + pos);
}
window.status = scroller;
setTimeout("scrolling()", 100);
}