Click to See Complete Forum and Search --> : Arrays and timerz


krautinator
10-02-2003, 09:27 AM
yes, I'm a newbie, but I don't care, I need help

just had to get that off my shoulderz

ok
I want to create a message that prints out when my users come to my web page using document.write, but I want to use an array with the sentence in it, in conjunction w/ a timer, so that it will look kinda like it's be typed out by a person, I have been fidgeting with this code for HOURS, can some one plz help me:
herez the code I do have, what's wrong w/ it?(everthing?hopefully not)


function Array()

{

var PrintOut = ('h','e','l','l','o','\0');
var timerId;
for(x=0;x<PrintOut.length;x++)
{

timerId=setTimeout(Document.write(PrintOut[x]),200);
clearTimeout(timerId;)
}

}


then I have it call the function when it loads the page:

<body onLoad="Array()">

I could do this so easily in C++:mad:

Khalid Ali
10-02-2003, 11:03 AM
Here is better script(IMHO)...:D

<script type="text/javascript">
var n=0,ctr=0;
var PrintOut = "This string will be printed as if its being typed.";
function Printer(n){
var timerId;
ctr=n;
if(n<PrintOut.length){
var obj = document.getElementById("div_1");
obj.innerHTML+=PrintOut.charAt(ctr);
ctr++;
setTimeout('Printer(ctr)',400);
}
}
</script>
</head>
<body onLoad="Printer(0)">
<div id="div_1" class="table-with-thin-border"></div>

krautinator
10-02-2003, 11:27 AM
Thank You!!!!

yeah, I figured on using strings, but didn't know the syntax for them,

one last small question, how would I change the font? (color and face, more specifically)

again thank you for your help

Khalid Ali
10-02-2003, 11:29 AM
set the style for div element as below

<div id="div_1" style="color:green;font-family:sans-serif;">