Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Dec 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Countdown help please

    hello guys,

    need help with my javascript code, basically i am trying to show countdown timer... this is my code and it works fine when page is loaded but the time is not ticking and it gives javascript error("Object required, line1, char1)...


    <html>
    <head>
    <title>WebForm4</title>
    <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
    <meta name="CODE_LANGUAGE" Content="C#">
    <meta name=vs_defaultClientScript content="JavaScript">
    <meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
    <script language="JavaScript" type="text/javascript">

    function countdown_clock(year, month, day, hour, minute, format)
    {
    html_code = '<div id="countdown"></div>';
    document.write(html_code);
    countdown(year, month, day, hour, minute, format);
    }

    function countdown(year, month, day, hour, minute, format)
    {
    Today = new Date();
    Todays_Year = Today.getFullYear() - 2000;
    Todays_Month = Today.getMonth() + 1;

    //Convert both today's date and the target date into miliseconds.
    Todays_Date = (new Date(Todays_Year, Todays_Month, Today.getDate(),
    Today.getHours(), Today.getMinutes(), Today.getSeconds())).getTime();
    Target_Date = (new Date(year, month, day, hour, minute, 00)).getTime();
    //Find their difference, and convert that into seconds.
    Time_Left = Math.round((Target_Date - Todays_Date) / 1000);
    if(Time_Left < 0)
    Time_Left = 0;


    //More datailed.
    days = Math.floor(Time_Left / (60 * 60 * 24));
    Time_Left %= (60 * 60 * 24);

    hours = Math.floor(Time_Left / (60 * 60));
    Time_Left %= (60 * 60);
    minutes = Math.floor(Time_Left / 60);
    Time_Left %= 60;
    seconds = Time_Left;


    var stext = days + ' days' + ' ';
    stext += hours + ' hours' + ' ';
    stext += minutes + ' minutes' + ' and ';
    stext += seconds + ' seconds' ;

    document.write(stext);
    //Recursive call, keeps the clock ticking.
    setTimeout('countdown(' + year + ',' + month + ',' + day + ',' + hour + ',' + minute + ',' + format + ');', 1000);
    }

    </script>
    <script type="text/javascript">countdown_clock(05, 12, 25, 00, 00, 1);</script>
    </head>
    <body MS_POSITIONING="GridLayout">

    <form id="form1" name="form1" method="post" runat="server">
    <div id="countdown"></div>
    <span id="s1">Hello</span>

    </form>

    </body>
    </html>

    Thanks
    newbeeee

  • #2
    Regular Coder Ranger56's Avatar
    Join Date
    Mar 2005
    Location
    Kent, WA.
    Posts
    783
    Thanks
    0
    Thanked 0 Times in 0 Posts
    http://stuff.spiderseatbabies.com/countdown.html

    view the source of that page, it's pretty easy to change

  • #3
    New to the CF scene
    Join Date
    Dec 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thanks....but

    can u please guide me how to write javascript for countdown between two times....like example
    servertime : 12:00AM
    Clienttime: 2:00AM
    Countdown should start 2hr 00min 00sec
    1hr 59min 01sec
    1hr 59min 02sec
    1hr 59min 03sec.....................
    00hr 00min 02sec...............

    Thanks

  • #4
    Regular Coder Ranger56's Avatar
    Join Date
    Mar 2005
    Location
    Kent, WA.
    Posts
    783
    Thanks
    0
    Thanked 0 Times in 0 Posts
    nope.

  • #5
    Banned
    Join Date
    Oct 2005
    Location
    I'm in GMT -5
    Posts
    314
    Thanks
    0
    Thanked 1 Time in 1 Post
    Code:
    <html>
    <head>
    <script type="text/javascript">
    
    	var refDate = new Date('2006 April 1 12:00')
    	var GMToffset = -5;
    	
    	function update(){
    
    		var nForm = document.forms.countDown;
    		var currDate = new Date();
    		currDate.setHours(GMToffset+currDate.getHours()+currDate.getTimezoneOffset()/60);
    		var remTime = refDate-currDate;
    		var nDays = parseInt(remTime/86400000);
    		var nHours = parseInt((remTime-(nDays*86400000))/3600000);
    		var nMin = parseInt((remTime-(nDays*86400000)-(nHours*3600000))/60000);
    		var nSec = 60-(currDate.getSeconds());
    		var nYears = parseInt(nDays/365);
    		var nMonths = parseInt((nDays-(nYears*365))/30);
    		var rDays = parseInt((nDays-(nYears*365)-(nMonths*30)));
    		if (nYears < 10){nYears = "0"+nYears}
    		if (nMonths < 10){nMonths = "0"+nMonths}
    		if (rDays < 10){rDays = "0"+rDays}
    		if (nHours < 10){nHours = "0"+nHours}
    		if (nMin < 10){nMin = "0"+nMin}
    		if (nSec < 10){nSec = "0"+nSec}
    		if (nSec == 60){nSec = "00"}
    		nForm.years.value = nYears;
    		nForm.months.value = nMonths;
    		nForm.days.value = rDays;
    		nForm.hours.value = nHours;
    		nForm.minutes.value = nMin;
    		nForm.seconds.value = nSec;
    		setTimeout("update()",1000);
    	}
    
    	window.onload=update;
    
    </script>
    </head>
    <body>
    <form name='countDown'>
    <p style='font-size:14pt'>Countdown To April 1, 2006, at 12:00:00 GMT-5:</p>
    Years: <input type='text' name='years' size='5' readonly>
    Months: <input type='text' name='months' size='5' readonly>
    Days: <input type='text' name='days' size='5' readonly>
    Hours: <input type='text' name='hours' size='5' readonly>
    Minutes: <input type='text' name="minutes" size='5' readonly>
    Seconds: <input type='text' name="seconds" size='5' readonly> 
    </form>
    </body>
    </html>
    Last edited by Ancora; 12-23-2005 at 08:32 PM.

  • #6
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,519
    Thanks
    3
    Thanked 507 Times in 494 Posts
    diabolical comes to mind

    Code:
    <html>
    <head>
    <title>WebForm4</title>
    <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
    <meta name="CODE_LANGUAGE" Content="C#">
    <meta name=vs_defaultClientScript content="JavaScript">
    <meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
    <script language="JavaScript" type="text/javascript">
    
    
    function countdown(year, month, day, hour, minute, format)
    {
    Today = new Date();
    Todays_Year = Today.getFullYear() - 2000;
    Todays_Month = Today.getMonth() + 1;
    
    //Convert both today's date and the target date into miliseconds.
    Todays_Date = (new Date(Todays_Year, Todays_Month, Today.getDate(),Today.getHours(), Today.getMinutes(), Today.getSeconds())).getTime();
    Target_Date = (new Date(year, month, day, hour, minute, 00)).getTime();
    //Find their difference, and convert that into seconds.
    Time_Left = Math.round((Target_Date - Todays_Date) / 1000);
    if(Time_Left < 0)
    Time_Left = 0;
    
    
    //More datailed.
    days = Math.floor(Time_Left / (60 * 60 * 24));
    Time_Left %= (60 * 60 * 24);
    
    hours = Math.floor(Time_Left / (60 * 60));
    Time_Left %= (60 * 60);
    minutes = Math.floor(Time_Left / 60);
    Time_Left %= 60;
    seconds = Time_Left;
    
    
    var stext = days + ' days' + ' ';
    stext += hours + ' hours' + ' ';
    stext += minutes + ' minutes' + ' and ';
    stext += seconds + ' seconds' ;
    document.getElementById('CountDownDiv').innerHTML=stext;
    //Recursive call, keeps the clock ticking.
    setTimeout('countdown(' + year + ',' + month + ',' + day + ',' + hour + ',' + minute + ',' + format + ');', 1000);
    }
    
    </script>
    </head>
    <body MS_POSITIONING="GridLayout" onload="countdown(05, 12, 25, 00, 00, 1);" >
    
    <form id="form1" name="form1" method="post" runat="server">
    <div id="CountDownDiv" ></div>
    <span id="s1">Hello</span>
    
    </form>
    
    </body>
    </html>
    did not see previous posts but will leave my mods


  •  

    Posting Permissions

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