Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: Echo in parts

  1. #1
    Regular Coder
    Join Date
    Aug 2006
    Posts
    181
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Echo in parts

    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?

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    I'd use Javascript for this, with the setInterval() function.

    first thing that popped up on google for +javascript +setInterval

  • #3
    Regular Coder
    Join Date
    Aug 2006
    Posts
    181
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hm, don't quite understand javascript that well (not at all:s)

  • #4
    Regular Coder
    Join Date
    Aug 2006
    Posts
    181
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #5
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    OK, well, here's a good code example. 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:
    PHP Code:
    <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:
    PHP Code:
    <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:
    PHP Code:
    <div ID="messageID"></div>

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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •