Is it possible to do this with JavaScript? (Resolved)

KeyserSoze

Diamond Member
Oct 11, 2000
6,048
1
81
What I'm trying to do, is output one letter at a time like somone is typing. (For a real short sentence.) Then, have it do it again, over and over. I once did this in C++, but obviously we had pointers to work with. And then just display a "sleep()" in there.

I'm not TOO experienced with JavaScript, but I'm searching all the free sites. I know it's pretty "dynamic", so I'm not sure if it can be done or not.

Any help or guidance to one of the better script sites would definitely be appreciated.


Thanks in Advance.


Edit: Ok, I found this page which sort of does what I want it to. But anyway to do it without the Text Area? Like just straight on the page?


KeyserSoze
 

eklass

Golden Member
Mar 19, 2001
1,218
0
0
i'm not real experienced with javascript and page elements, however my guess is that you woudl put a div on the page somewhere like:

<div id="typeMe"></div>

and then do something to the effect of looping through and changing document.typeMe.content (no i don't know the actual object and property)
 

Barnaby W. Füi

Elite Member
Aug 14, 2001
12,343
0
0
Well, you can do document.write, so I'm sure you can write to arbitrary objects in the document (but like eklass, I don't know exactly how :p)
 

jonmullen

Platinum Member
Jun 17, 2002
2,517
0
0
Put this in this in the <HEAD>:

<script language="JavaScript">
function dothis(){
document.getElementById('typeme').innerHTML = document.getElementById('typeme').innerHTML+string.charAt(pos);
pos++;
}
function typethis(str){
string = new String(str);
inv = 500; //adjust this for the delay between the typing strokes...it is in milliseconds...so 500 is half a second and 1000 is a second.
i = 500
pos = 0;
for(posistion = 0; posistion < string.length;posistion++)
{
mytimer = setTimeout("dothis()",i);
i = i + inv;
}
}
</script>

now put this <span>:

<span id="typeme"></span>

now after the span put this function call:

<script language="JavaScript">
typethis("String you want to have typed out");
</script>
 

KeyserSoze

Diamond Member
Oct 11, 2000
6,048
1
81
Thanks jonmullen, I'll try that tonite, and post back here.

(And to the others who posted, but you really weren't much help, were you? :p)




KeyserSoze





 

KeyserSoze

Diamond Member
Oct 11, 2000
6,048
1
81
Originally posted by: jonmullen
[checkup] is it working for you? [/checkup]


Yes, it worked exactly as I wanted. I was having problems with the text color when I tried setting it through straight HTML. Then I eventually realized that it was the javascript that was doing the 'writing', so I'm sure that's gonna be easy enough to fix.

Thanks again.

(Just so you know, this is a little dorky site for me and my friends. I would NEVER put something like this in a real site.)



KeyserSoze
 

jonmullen

Platinum Member
Jun 17, 2002
2,517
0
0
well thats good...as for the text issue, the easiest way to change to color since it is just putting the text into a span is to use CSS to change the color of every thing in the span. Just put this in the head of the page:

<style type="text/css">
#typeme{
color:red; #this can be a basic color or a HEX value
}
</style>