Results 1 to 9 of 9

Thread: code needed for clock countdown script

  1. #1
    Join Date
    Feb 2005
    Posts
    153
    Thanks
    3
    Thanked 2 Times in 2 Posts

    Default code needed for clock countdown script

    OK, im trying to get working a countdown clock for a kind of game im doing.

    Basically I need the clock to have only minutes and seconds, and it counts down from say 10 minutes from whenever the user enters the site.

    I understand this may need to be java script as I want people to actually see the minutes and seconds tick away.
    When the time is up, I need the page to be re-directed to a new page which will state that their time is up- game over etc

    As this game spans over 48 web pages, the clock obviously needs to carry forward its time (minutes remaining) over to each page.
    Ideally I would like the 'clock/timer' to float at the top of each screen (perhaps with CSS?).

    Can anyone help with this?

    Even if someone has this code in asp (rather than php) it would be of great help. :-)

  2. #2
    Join Date
    Mar 2006
    Posts
    97
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi

    Take a look at this see if it's any hekp
    http://www.test.spire-applications.co.uk/

    I am not a javascipt wiz so don't know if it will be any good, perhaps u would be able to modify it

  3. #3
    Join Date
    Feb 2005
    Posts
    153
    Thanks
    3
    Thanked 2 Times in 2 Posts

    Default

    thanks but thats just a clock...... I need something far more sophsticated that this!!! :-(

  4. #4
    Join Date
    Mar 2005
    Location
    Isle of Man
    Posts
    1,261
    Thanks
    3
    Thanked 24 Times in 24 Posts

    Default

    Quote Originally Posted by GarethMoore1979
    OK, im trying to get working a countdown clock for a kind of game im doing.

    Basically I need the clock to have only minutes and seconds, and it counts down from say 10 minutes from whenever the user enters the site.

    I understand this may need to be java script as I want people to actually see the minutes and seconds tick away.
    When the time is up, I need the page to be re-directed to a new page which will state that their time is up- game over etc

    As this game spans over 48 web pages, the clock obviously needs to carry forward its time (minutes remaining) over to each page.
    Ideally I would like the 'clock/timer' to float at the top of each screen (perhaps with CSS?).

    Can anyone help with this?

    Even if someone has this code in asp (rather than php) it would be of great help. :-)
    Thought about using flash? lol

    Yeah, you are not going to have a live countdown clock using PHP (certainly without the buffer being flushed as ), so javascript is the way forward to display the time. There are loads of snippets if you google.
    My first thought would be to set a cookie on the first page containing the current timestamp, so that you know when the game started. Then on each consecutive page you would use that cookie's timestamp against the current time (which you could store in the cookie too, set from php to avoiding relying on the client's clock) to set the javascript clock.

    Back on the server-side you could use the cookie information to keep track of the game time as well, which would mean it would still function without javascript.

  5. #5
    Join Date
    Feb 2005
    Posts
    153
    Thanks
    3
    Thanked 2 Times in 2 Posts

    Default

    Im not all that great with flash....but this game originally started out as simple html pages, now the person im developing for wants this clock.

    Anyway this could work I think using 2 seperate things....

    as you say a cookie which sets the time the game started and on each page (in the background) it would check that it still has "time left".

    The java clock would run seperate and would mearly be there as effect.
    But this java clock would still in some way have to take the time started from the cookie!!! :crying:

    I have done a google search but this was my last resort.....nothing I need quite fits as its integrating hp and JS together.

  6. #6
    Join Date
    Mar 2005
    Location
    Isle of Man
    Posts
    1,261
    Thanks
    3
    Thanked 24 Times in 24 Posts

    Default

    Quote Originally Posted by GarethMoore1979
    Im not all that great with flash....but this game originally started out as simple html pages, now the person im developing for wants this clock.

    Anyway this could work I think using 2 seperate things....

    as you say a cookie which sets the time the game started and on each page (in the background) it would check that it still has "time left".

    The java clock would run seperate and would mearly be there as effect.
    But this java clock would still in some way have to take the time started from the cookie!!! :crying:

    I have done a google search but this was my last resort.....nothing I need quite fits as its integrating hp and JS together.
    I'm not that great with javascript but...
    Code:
    	<form name="clock_form">
    	    <input type=text name="clock" />
    	</form>
    	<script language="JavaScript">
    	    <!-- Hide from non JavaScript browsers
    		function timer(currentTime)
    	    {
    		document.clock_form.clock.value = currentTime;
    		document.clock_form.clock.blur();
    		newTime = currentTime+1;
    		setTimeout("timer(newTime)", 1000);
    	    }
    		//if you don't want to rely on client's clock, get these from your cookie
    		gameStarted = new Date("June 14 2006 15:15");
    		pageLoaded = new Date();
    		startTime = Math.round((pageLoaded - gameStarted)/1000);
    	    timer(startTime);
    	    // End of clock -->
    	</script>
    I would imagine setting up those gameStarterd and pageLoaded variables using the values we talked about stored in your cookies.
    Any help?

  7. #7
    Join Date
    Feb 2005
    Posts
    153
    Thanks
    3
    Thanked 2 Times in 2 Posts

    Default

    thanks Nick..... but this displays in seconds, ideally I need Minutes and seconds.

    but I dont know any JS at all, soim unsure of where to add my variables from cookie into this.

  8. #8
    Join Date
    Mar 2005
    Location
    Isle of Man
    Posts
    1,261
    Thanks
    3
    Thanked 24 Times in 24 Posts

    Default

    Quote Originally Posted by GarethMoore1979
    thanks Nick..... but this displays in seconds, ideally I need Minutes and seconds.

    but I dont know any JS at all, soim unsure of where to add my variables from cookie into this.
    There are loads of Javascript functions if you google that get and set cookies. Here is just one at random.
    Converting seconds to minutes and seconds will be really easy am pretty sure you can use a modulus operator (%). Anyway, have a look at the cookies and I'll paste you JS to format the clock later if you need it.
    ______
    EDIT
    in fact here you go, add these lines in to the previous snippet:
    Code:
    [...]
    function timer(currentTime)
    {
        seconds = currentTime % 60;
        minutes = Math.floor(currentTime/60);
        document.clock_form.clock.value = minutes+" minutes "+seconds+" seconds";
    [...]
    Last edited by nick; 14th June 2006 at 07:36 PM.

  9. #9
    Join Date
    Feb 2005
    Posts
    153
    Thanks
    3
    Thanked 2 Times in 2 Posts

    Default

    Thanks Nick your a great help. However I need this script to count down, not up. Now, I have found the following script that does what I want. It countsdown from 10 mins (or however many mins are specified at the top).

    But this starts counting from the current time. I need it to count from the time in the cookie. Ive tried to alter this script for the past 3 hours but im getting nowhere. :crying: :crying:

    So....I need on the first page to set the cookie.

    I then need to change the following script to take the time from the cookie and count down from there instead of the current time.

    Without pushing my luck, ideally I need the script to re-direct to a new set page when the counter reaches 0:00


    PHP Code:
    <HTML
    <
    HEAD
    <
    TITLE>Countdown Clock</TITLE
    <
    SCRIPT
    <!-- 
    var 
    timeInMin "30"//The minutes the count down should run. 

    var theDay = new Date() 
    var 
    countDown theDay.getTime()+(1000*60*timeInMin);
    var 
    TimeTill //The string that is going to put all numbers together and make sense. 

    function countdown() 

    var 
    today = new Date() //Create an Date Object that contains today's date. 
    var second Math.floor((countDown today.getTime())/1000
    /*Use getTime() to get the milisecond (1/1000 of a second) from now to theDay. 
    and devide it into 1000 to get the seconds from now to theDay.*/ 


    var minute Math.floor(second/60//Devide "second" into 60 to get the minute 
    var hour Math.floor(minute/60//Devide "minute" into 60 to get the hour 
    var day Math.floor(hour/24//Devide "hour" into 60 to get the day 

    CDayday //Correct day 
    CHourhour 24 //Correct hour, after devide into 24, the remainder deposits here. 
    CMinuteminute 60 //Correct minute, after devide into 60, the remainder deposits here. 
    CSecondsecond 60 //Correct second, after devide into 60, the remainder deposits here. 

    var TimeTill "";

    if(
    CDay)
    {
    TimeTill += CDay ":";
    }
    if(
    CHour || CDay)
    {
    if(
    CHour 10)
    {
    TimeTill += "0";
    }
    TimeTill += CHour ":";
    }
    if(
    CMinute 10)
    {
    TimeTill += "0";
    }
    TimeTill += CMinute ":";
    if(
    CSecond 10)
    {
    TimeTill += "0";
    }
    TimeTill += CSecond;

    document.clock.countdown.value TimeTill //Make the particular form chart become "Daytill" 
    var counter setTimeout("countdown()"1000//Create the timer "counter" that will automatic restart function countdown() again every second. 

    //--> 
    </SCRIPT> 
    </HEAD> 
    <BODY onLoad = "countdown()"> 
    <FORM NAME = "clock"> 
    <INPUT TYPE="TEXT" NAME="countdown" size="20" class="abc"><BR> 
    </FORM> 
    </BODY> 
    </HTML> 

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. ASP Files Display Code In Browser
    By MWF in forum ASP (VBScript)
    Replies: 9
    Last Post: 26th July 2006, 01:24 PM
  2. Which form to email ASP Code
    By s80wkr in forum Technical Support
    Replies: 1
    Last Post: 31st May 2006, 03:08 PM
  3. Basic first time website & SQL2005 setup - help needed
    By theonlinecleaningshop in forum Technical Support
    Replies: 6
    Last Post: 5th March 2006, 12:12 PM
  4. browserCaps code
    By jaimalchohan in forum ASP.NET
    Replies: 0
    Last Post: 9th November 2005, 03:08 PM
  5. Flash Designer/Developer Needed
    By Shiven Rabadia in forum For Sale, Sites and Services
    Replies: 0
    Last Post: 20th October 2005, 01:58 PM

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
  •