Results 1 to 3 of 3

Thread: Setting timer on message

  1. #1
    Join Date
    Mar 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Setting timer on message

    Hi guys!

    I need a code that displays a message after a duration of 3 seconds, I have an idea of code organization but I can't make it work coz I dont know some of the things!!!!

    var visitorMsg1 = "Welcome visitor 1";
    var visitorMsg2 = "Welcome visitor 2";

    var durationTime = 0;

    if(durationTime == 3){
    document.write(visitorMsg1);
    }
    else{
    document.write(visitorMsg2);
    }

  2. #2
    Join Date
    Feb 2007
    Posts
    293
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    You can use setTimeout to make something happen after a given period of time. The number reflects milliseconds, so 3000 equals 3 seconds.
    Also, using innerHTML will give you more flexibility than document.write, since document.write will re-write the entire page.


    Code:
    <html>
    <head>
    <script type="text/javascript">
    var visitorMsg1 = "Welcome visitor 1";
    var visitorMsg2 = "Welcome visitor 2";
    setTimeout('message2()', 3000);
    function message2()
    	{
    		document.getElementById('message2').innerHTML = visitorMsg2;
    	}
    </script>
    </head>
    <body>
    <p id="message2">
    <script type="text/javascript">
    document.write(visitorMsg1);
    </script>
    </p>
    </body>
    </html>
    If you want to keep message 1 and add message 2, modify it like this
    Code:
    <p id="message1">
    <script type="text/javascript">
    document.write(visitorMsg1);
    </script>
    </p>
    <p id="message2">
    </p>

  3. #3
    Join Date
    Mar 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Thanx a million

    Hi Veronica,

    Thanks a lot u have solved a huge problem I had. now I can go ahead with my application.....

    thanx once again...
    Willy

Bookmarks

Posting Permissions

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