Web Analytics Made Easy -
StatCounter Help with setInterval - CodingForum

Announcement

Collapse
No announcement yet.

Help with setInterval

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Resolved Help with setInterval

    Good day one and all, it seems I need help once more.

    I have this javascript:

    Code:
    var counter = 0;
    var wooYayIntervalId;
    var wooYayIntervalId2;
    
    function wooYayClickHandler ( )
    {
        
        // Start the timer
        document.getElementById("wooYayMessage").innerHTML = counter;
        wooYayIntervalId =  setInterval ( "wooYay()", 2500  );
    }
    
    function wooYay ( )
    {
        
        if(counter <= 4)
        {
            counter++;
            document.getElementById("wooYayMessage").innerHTML = counter;
            wooYayIntervalId2 = setInterval ( "wooYayClickHandler ( )", 2500 );
        }
        else
        {
            clearInterval (wooYayIntervalId);
            clearInterval (wooYayIntervalId2);
        }
    }
    It works pretty well, except when the counter gets to 3 it just seems to skip over it and I don't know why.

    Then it is supposed to go into this php file.
    Code:
    <?php
    include_once "class.sql.php";
    $sql = new SQL();
    
    $GameID = $_GET['ID'];
    $Numbers = $sql->GetWinningNumbers($GameID);
    
    ?>
    
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html>
    <head>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
    <title>Bingo Game Extravaganza</title>
    <link rel='stylesheet' type='text/css' href='style.css' />
    
    <script type='text/javascript' src="DrawNumber.js">
    </script>
    
    </head>
    <body onLoad="wooYayClickHandler()">
    <form >
    
    <div id="wooYayMessage" style="height: 1.5em; font-size: 2em; color: red;"></div>
    
    </form>
    </body>
    </html>
    Also I should mention that I'm going to use the $Numbers array with the javascript later to make the script draw numbers from it at a 10 second interval and print them out, so if you have any advice on that it would help me out alot.

    Thanks in advance.

    PS. I hope I put this in the right category if I didn't I'm really sorry.
    Last edited by Deadeye; Apr 9, 2009, 10:58 AM.

  • #2
    Change setInterval to setTimeout throughout.

    The div then shows 0,1,2,3,4,5 in sequence at 2.5 second intervals, which I take it is what you want.


    "There is no reason anyone would want a computer in their home." - Ken Olson, President/Founder of Digital Equipment Corp., 1977.


    BTW, the time to say "thanks" is afterwards, not beforehand which gives the impression that you take other people's unpaid assistance for granted. Or as British politician Neil Kinnock put it, "Don't belch before you have had the meal." Prefer to use "please" beforehand and if you find a response helpful then you can use the "Thank User For This Post" button.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

    Comment


    • #3
      Thanks a lot, that did the trick.

      Could you maybe explain why this was happening, and also when do I use setInterval and when do I use setTimeout. I want to know so I don't make mistakes like this in the future.

      About the thanks in advance bit, I do it mostly because it has become a habit when I post something to add it to the bottom since I don't know how to end forum posts or start them (as you might notice from my other threads), didn't mean to imply that I was taking everybody's assistance for granted. English is not my primary language so I miss stuff like that, sorry .

      Comment


      • #4
        Originally posted by Deadeye View Post
        Thanks a lot, that did the trick.

        Could you maybe explain why this was happening, and also when do I use setInterval and when do I use setTimeout. I want to know so I don't make mistakes like this in the future.

        Have a look at:-
        http://www.elated.com/articles/javas...d-setinterval/

        The important difference is that, whereas setTimeout() triggers expression only once, setInterval() keeps triggering expression again and again (unless you tell it to stop).



        Originally posted by Deadeye View Post
        About the thanks in advance bit, I do it mostly because it has become a habit when I post something to add it to the bottom since I don't know how to end forum posts or start them (as you might notice from my other threads), didn't mean to imply that I was taking everybody's assistance for granted. English is not my primary language so I miss stuff like that, sorry .

        Well, you seem to speak (or write) English perfectly, and better than some native speakers we encounter here.

        All the code given in this post has been tested and is intended to address the question asked.
        Unless stated otherwise it is not just a demonstration.

        Comment


        • #5
          That explained it nicely, thank you once more.

          Comment

          Working...
          X