I am (obviously) extremely new to javascript. I need to have this script execute once, then quit. I've tried several commands but I must be an idiot...could someone please help me modify it? Thanks so much...

<!-- Begin
var speed = 5;
var cycledelay = 1000;
var maxsize = 28;

var x = 0;
var y = 0;
var themessage, size;
var esize = "</font>";

function initArray() {
this.length = initArray.arguments.length;
for (var i = 0; i < this.length; i++) {
this[i] = initArray.arguments[i];
   }
}
var themessage2 = new initArray(
"text here",
"removed because",
"its an ad for",
"my business"
);
if(navigator.appName == "Netscape")
document.write('<layer id="wds"></layer><br>');
if (navigator.appVersion.indexOf("MSIE") != -1)
document.write('<span id="wds"></span><br>');
function upwords(){ 
themessage = themessage2[y];
if (x < maxsize) {
x++;
setTimeout("upwords()",speed);
}
else setTimeout("downwords()",cycledelay);

if(navigator.appName == "Netscape") {
size = "<font point-size='"+x+"pt'>"; 
document.wds.document.write(size+"<left><font color=#FFFF00>"+themessage+"</font></left>"+esize);
document.wds.document.close();
}
if (navigator.appVersion.indexOf("MSIE") != -1){
wds.innerHTML = "<left><font color=#FFFF00>"+themessage+"</font></left>";
wds.style.fontSize=x+'px';
   }
} 
function downwords(){
if (x > 1) {
x--;
setTimeout("downwords()",speed);
}
else {
setTimeout("upwords()",cycledelay);
y++;
if (y > themessage2.length - 1) y = 0;
}
if(navigator.appName == "Netscape") {
size = "<font point-size='"+x+"pt'>"; 
document.wds.document.write(size+"<left><font color=#66FF00>"+themessage+"</font></left>"+esize);
document.wds.document.close();
}
if (navigator.appVersion.indexOf("MSIE") != -1){
wds.innerHTML = "<left><font color=#66FF00>"+themessage+"</font></left>";
wds.style.fontSize=x+'px'
   }
}
setTimeout("upwords()",speed);
//  End -->

I enclosed the script (after global declarations) in a function called runOnetime and set iterations to one - I think. Here it is:

var speed = 5;
var cycledelay = 1000;
var maxsize = 28;

var x = 0;
var y = 0;
var themessage, size;
var esize = "</font>";

[B]function runOnetime () {
for(var its=0; its<2; its++){
[/B]
function initArray() {
this.length = initArray.arguments.length;
for (var i = 0; i < this.length; i++) {
this[i] = initArray.arguments[i];
   }
}
...

and I added the necessary 2 closures after the last line in the script (before the "end" remark). Instead of running continuously, now the script doesn't execute at all and I get no errors...aargh. What I'm doing wrong has to be something obvious but I just can't see it. Help?

Maybe this would help!

<html>
<head>
<title><!--Sample--></title>
<script type="text/javascript">
<!--


window.onload = myMessage; function myMessage()
{
var m = [ 'Hello', 'How are you?', 'Hope your enjoying my simple script!', 'I hope this will help with what you need!', 'Enjoy Javascripting...',  'Function Ended!'];
n = 0;
var stopMe = setTimeout('myMessage()', 1000); 
if ( stopMe == 6 ) {  clearTimeout( stopMe ); alert('I\'m done!'); } 
do
{ 
document.getElementById('txt').innerHTML = m[n];
n++ } while( n < stopMe )
 }
//-->
</script>
</head>
<body>
<p align="center"> 

<span id="txt"></span>
<p>
</body>
</html>

Thanks so much! I really appreciate your time. BTW, can you recommend a *good* online javascript tutorial? One that addresses any cross-browser issues? I'd really appreciate it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.