Results 1 to 6 of 6

Thread: Settimeout2

  1. #1
    gencoglu
    Guest

    Settimeout2

    hELLO
    I have just tried to write asmall script but...
    I had some problems..
    ***using settimeout....I wanted my program to alert me (helloooo)...when the "seconds==5//// and then when the seconds==10 ..let it say "goodmorning" or change bgcolor to red or showme an image if the second ==20...

    Hope you got me..Thanks

  2. #2
    PowerPoster sail3005's Avatar
    Join Date
    Oct 2000
    Location
    Chicago, IL, USA
    Posts
    2,340
    post your code....

    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA

  3. #3
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    Code:
    <head>
    <script language="JavaScript">
       var number = 0;
       function timer() {
          time = setTimeout("randomEvent()",5000);
       }
       function randomEvent() {
          switch(number) {
            case 0:
              alert("Hello");
            break;
            case 1:
              document.bgColor = "#CC0000";
            break;
            case 2:
              window.open("image.html");
            break;
          }
          number++;
          if (number == 3)
            number = 0;
          clearTimeout(time);
          timer();
       }
    </script>
    </head>
    
    <body onLoad="timer();" bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">
    
    </body>
    -Matt
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    try this


    Code:
    <head>
    <script language="JavaScript">
       var number = 0;
     var timeincrement = 5000;
    
       function timer() {
          time = setTimeout("randomEvent()",timeincrement);
         timeincrement += 5000;  
    }
       function randomEvent() {
          switch(number) {
            case 0:
              alert("Hello");
            break;
            case 1:
              document.bgColor = "#CC0000";
            break;
            case 2:
              window.open("image.html");
            break;
          }
          number++;
          if (number == 3)
            number = 0;
          clearTimeout(time);
          timer();
       }
    </script>
    </head>
    
    <body onLoad="timer();" bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">
    
    </body>

  5. #5
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    Originally posted by mendhak
    try this


    Code:
    <head>
    <script language="JavaScript">
       var number = 0;
     var timeincrement = 5000;
    
       function timer() {
          time = setTimeout("randomEvent()",timeincrement);
         timeincrement += 5000;  
    }
       function randomEvent() {
          switch(number) {
            case 0:
              alert("Hello");
            break;
            case 1:
              document.bgColor = "#CC0000";
            break;
            case 2:
              window.open("image.html");
            break;
          }
          number++;
          if (number == 3)
            number = 0;
          clearTimeout(time);
          timer();
       }
    </script>
    </head>
    
    <body onLoad="timer();" bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">
    
    </body>
    Doing it that way produces the alert at 5 seconds, but then the background change happens at 15 seconds and not 10.

    Whereas on mine, I just reset the timer so it runs another 5 seconds which when added with the before 5 seconds it equals 10 and not 15.

    -Matt
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Houston, we're experiencing communication and interpretation problems here! Get me outta here!

Posting Permissions

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



Click Here to Expand Forum to Full Width