...

View Full Version : Echo in parts



arne2
08-25-2006, 05:32 PM
Hi,
is there a way to echo (doesn't have to be php) out sentences to a page with some time between, like for example :

MESSAGE1 (and then 10secs later below the first message appears:)
MESSAGE2

It may also be that it changes the text (so: message 1 => message 2 after 10secs).

I thought maybe the sleep() function but it doesn't output anything before the page is fully loaded, does it?

Fumigator
08-25-2006, 05:40 PM
I'd use Javascript for this, with the setInterval() function.

first thing that popped up on google for +javascript +setInterval (http://www.evolt.org/article/Using_setInterval_to_Make_a_JavaScript_Listener/17/36035/)

arne2
08-25-2006, 05:43 PM
hm, don't quite understand javascript that well :p (not at all:s)

arne2
08-25-2006, 05:53 PM
Googled some about the setinterval() function but can't seem to find out how i can print text in intervals with it. Can you tell me a little more about the how-to?

Fumigator
08-25-2006, 06:35 PM
OK, well, here's a good code example (http://www.devguru.com/Technologies/ecmaScript/quickref/win_setinterval.html). Once you establish that a function will be executed every so often, then simply put the code to display a message inside that function.

How you go about displaying a message from your Javascript function is up to you.

You can use a read only input field or textarea field:


<input type="text" name="messageText">
<script type="text/javascript">
function changeMsg(newMsg) {
document.messageText.value = newMsg;
}
<script>


Or you can use the document.writeln() function to directly output the message:


<script type="text/javascript">
function changeMsg(newMsg) {
document.writeln(newMsg);
}
<script>


Or you can access and change any text on your page using document.getElementById('messageID').innerHTML, where messageID is the ID of the tag you want to change:


<div ID="messageID"></div>

<script type="text/javascript">
function changeMsg(newMsg) {
document.getElementById('messageID').innerHTML = newMsg;
}
<script>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum