SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Addict
    Join Date
    Jan 2002
    Location
    Omaha, NE
    Posts
    281
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Simple Countdown help

    I'm looking for a little help with a countdown. I've tried a few things but just can't get them to work so i'm hoping someone out here can help me out. I'm looking for a javascript that will do a 3 minute countdown and display it on the screen, preferably not in a textbox, but i'm not picky.

    Here is how it works. Someone will make a selection from a form. The date/time of that selection is then stored in a database. I want to use the date time stored in the database as my starting time and then countdown 3 minutes. After 3 minutes I would like a message saying Times Up, please make a selection.

    Any ideas?

    Thanks in advance! Sitepoint Rocks!

  2. #2
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think you mentioned previously that your using php as your server side language. So make a simple query to your database and alter this value according to the value that the user has entered. The rest should be done using php and if the date matches use the peice of code below.

    var timer = 10;

    PHP Code:
    <html>
      <
    head>
        <
    style>

          
    body {
            
    margin:50px 0px;
            
    padding:0px;
            
    text-align:center;
          }

          
    table {
            
    border:solid 1px black;
            
    width:350px;
            
    height:250px;
            
    text-align:center;
          }

          
    tr {
            
    border:solid 1px black;
          }

          
    td {
            
    border:solid 1px black;
          }

        </
    style>

        <
    script>

          var 
    timer 10;  //Number of seconds to count down

          
    function countdown()
          {
            if(
    timer 0//if timer great than 0 it will continue to count down
            
    {
              
    document.all['swap'].innerHTML timer;  //swaps field in page
              
    timer -= 1;
              
    setTimeout("countdown()",1000); 
            }
            else
            {
              
    alert("Times Up, please make a selection");
            }
          }
        
    </script>
      </head>
      <body onload="countdown()">
        <table cellspacing="25">
          <tr>
            <td id="swap">timer</td>
          </tr>
        </table>

      </body>
    </html> 

  3. #3
    SitePoint Addict
    Join Date
    Jan 2002
    Location
    Omaha, NE
    Posts
    281
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Keep time with refresh...

    Andrew-J2000,

    Thanks for your help, I forgot a key point of information when I was explaining what I needed. As the user refreshes it needs to keep the time of the count down, not start at 10 again. When on makes a selection, the date is updated in the database. What I have tried is a countdown using a date. The start date is what is in the database, then the future date (the date counting down to) is 3 minutes in the future from the date in the database. I just can't get it to work. Can you enhance your script to do the above? I can get the date out of the database and populate the variables. I just can't get the countdown to execute.

    Thanks for your help!

  4. #4
    SitePoint Zealot
    Join Date
    Jul 2002
    Posts
    168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You should know that when a page is refreshed, all variables that were calculated by javascript functions called by that page are erased.
    The most simple way to make javascript information persistent is to store it in a cookie. If it is a continuously changing variable, this might be problematic. Don't know, maybe you could use something like onunload or something.
    (You'll have to ask yourself if it will be worth the trouble to make it work exactly like you envisioned or to make a compromise...)


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
  •