SitePoint Sponsor

User Tag List

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

    Countdown Script help

    I'm working on modifying a countdown script that i have downloaded.

    Using Coldfusion, I pull a date from a database and add 3 minutes to it. The script is supposed to count down 3 minutes and stop. For some reason when the starttime in the script and the endtime in the script are different days, the countdown works, when they are the same day it doesn't display. Any ideas for a fix? I haven't done alot with javascript so i'm sure this is pretty basic, but I just can't seem to crack it.

    Thanks for your help.

    You can also see the page at
    http://www.bstreetlounge.com/ffl/tsncountdownscript.cfm

    Code:
    <cfif isDefined("Draft")>
     <cfquery name="SetValue" datasource="#ffldsn#">
      Update ffl_prop
       set Propvalue = '#Dateformat(now(),"mm/dd/yyyy")# #Timeformat(now(),"HH:mm:ss")#'
      Where
       PropName = 'StartDraftTime' and leagueid = 5
     </cfquery>
    </cfif>
    
    <cfquery name="GetDraftTime" datasource="#ffldsn#">
     Select *
     from ffl_prop
     where leagueid = 5
    </cfquery>
    <!--- <cfdump var="#GetDraftTime#"> --->
    <html>
    <head>
     <title>Equipment Maintenance - Add</title>
    <cfset NewDateVal = DateAdd('n',3,GetDraftTime.propvalue)>
    <cfset YearVal = Year(NewDateVal)>
    <cfset MonthVal = Month(NewDateVal)>
    <cfset dayVal = Day(NewDateVal)>
    <cfset minval = minute(NewDateVal)>
    <cfset HourVal = Hour(NewDateVal)>
    <!--- <cfdump var="#NewDateVal#">
     var yr=<cfoutput>#yearval#</cfoutput>;<Br>
    var mo=<cfoutput>#Monthval#</cfoutput>;<br>
    var da=<cfoutput>#dayval#</cfoutput>;<br>
    var ho=<cfoutput>20</cfoutput>;<br>
    var mi=<cfoutput>#minval#</cfoutput>;<br>  --->
    <script>
    var yr=2003;
    var mo=8;
    var da=19;
    var ho=20;
    var mi=1;
    function countdown()
    {
       var today = new Date();
       var todayy = today.getYear();
       if(todayy < 1000)
       {
    	  todayy += 1900;
       }
       var todaym = today.getMonth();
       var todayd = today.getDate();
       var todayh = today.getHours();
       var todaymin = today.getMinutes();
       var todaysec = today.getSeconds();
       var todaystring = todaym+"/"+todayd+"/"+todayy+" "+todayh+":"+todaymin+":"+todaysec;
       futurestring = (mo-1)+"/"+da+"/"+yr+" "+ho+":"+mi+":"+"00";
       dd = Date.parse(futurestring)-Date.parse(todaystring);
       dday = Math.floor(dd/(60*60*1000*24)*1);
       dhour = Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1);
       dmin = Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1);
       dsec = Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1);
       if(document.getElementById)
       {
    	  //if on day of occasion
    	  if(todayy == yr && todaym == (mo-1) && todayd == da)
    	  {
    		 // need to handle this!!
    		 return;
    	  }
    	  //else, if not yet
    	  else
    	  {
    		 var countdownDiv = document.getElementById("countdown");
    		 countdownDiv.innerHTML = "<font color=#990000><b>" + dday + "</b> days</font> <b> " + dhour + "</b> h <b>" + dmin + "</b> m <b>" + dsec + "</b> s "; 
    		 setTimeout("countdown()",1000)
    	  }
       }
    }
    if(document.getElementById)
    {
       document.write("");
       document.write("<div id=countdown></div>");
       document.write("<br>");
       countdown();
    }
    else
    {
       document.write("");
       document.write("");
       document.write("<br>");
    }
    </script>
    </head>
    <body onload="countdown();">
    <form action="tsncountdownscript.cfm" method="post">
     <input type="submit" name="Draft" value="Submit">
    </form>
    </body>
    </html>
    "Oh, you hate your job? Why didn't you say so? There's a support group for that.
    It's called EVERYBODY, and they meet at the bar."

    --Drew Carey

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

    Just need the countdown to work now!

    Well I messed with the script a little bit and got the values to work. It loads the 3 min mark but then won't "countdown". Any ideas on why it won't countdown?

    Thanks in advance

    Code:
    <cfif isDefined("Draft")>
     <cfquery name="SetValue" datasource="">
      Update ffl_prop
       set Propvalue = '#Dateformat(now(),"mm/dd/yyyy")# #Timeformat(now(),"HH:mm:ss")#'
      Where
       PropName = 'StartDraftTime' and leagueid = 5
     </cfquery>
    </cfif>
    
    <cfquery name="GetDraftTime" datasource="">
     Select *
     from ffl_prop
     where leagueid = 5
    </cfquery>
    <!--- <cfdump var="#GetDraftTime#"> --->
    <html>
    <head>
     <title>Equipment Maintenance - Add</title>
     
    <cfset YearVal = Year(GetDraftTime.propvalue)>
    <cfset MonthVal = Month(GetDraftTime.propvalue)>
    <cfset dayVal = Day(GetDraftTime.propvalue)>
    <cfset minval = minute(GetDraftTime.propvalue)>
    <cfset HourVal = Hour(GetDraftTime.propvalue)>
    <cfset SecVal = Second(GetDraftTime.propvalue)> 
    <cfset NewDateVal = DateAdd('n',3,GetDraftTime.propvalue)>
    <cfset FYearVal = Year(NewDateVal)>
    <cfset FMonthVal = Month(NewDateVal)>
    <cfset FdayVal = Day(NewDateVal)>
    <cfset Fminval = minute(NewDateVal)>
    <cfset FHourVal = Hour(NewDateVal)>
    <cfset FSecVal = Second(NewDateVal)>
    
    <script>
    var yr=<cfoutput>#Fyearval#</cfoutput>;
    var mo=<cfoutput>#FMonthval#</cfoutput>;
    var da=<cfoutput>#Fdayval#</cfoutput>;
    var ho=<cfoutput>#FHourVal#</cfoutput>;
    var mi=<cfoutput>#Fminval#</cfoutput>;
    var sec = <cfoutput>#Fsecval#</cfoutput>;
    function countdown()
    {
       var today = new Date();
      // var todayy = today.getYear();
       var todayy = <cfoutput>#YearVal#</cfoutput>;
       if(todayy < 1000)
       {
    	  todayy += 1900;
       }
      // var todaym = today.getMonth();
      // var todayd = today.getDate();
    //   var todayh = today.getHours();
    //   var todaymin = today.getMinutes();
    //   var todaysec = today.getSeconds();
     //  var todaystring = todaym+"/"+todayd+"/"+todayy+" "+todayh+":"+todaymin+":"+todaysec;
     
       var todaym = <cfoutput>#MonthVal#</cfoutput>;
      var todayd = <cfoutput>#dayVal#</cfoutput>;
       var todayh = <cfoutput>#HourVal#</cfoutput>;
       var todaymin = <cfoutput>#MinVal#</cfoutput>;
       var todaysec = <cfoutput>#SecVal#</cfoutput>;
      var todaystring = todaym+"/"+todayd+"/"+todayy+" "+todayh+":"+todaymin+":"+todaysec;
       //futurestring = (mo-1)+"/"+da+"/"+yr+" "+ho+":"+mi+":"+"00";
       futurestring = mo+"/"+da+"/"+yr+" "+ho+":"+mi+":"+sec;
       dd = Date.parse(futurestring)-Date.parse(todaystring);
       dday = Math.floor(dd/(60*60*1000*24)*1);
       dhour = Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1);
       dmin = Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1);
       dsec = Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1);
       if(document.getElementById)
       {
    	  //if on day of occasion
    	  if(todayy == yr && todaym == (mo) && todayd == da)
    	  {
    		 // need to handle this!!
    	var countdownDiv = document.getElementById("countdown");
    		 countdownDiv.innerHTML = "<font color=#990000><b>" + dmin + "</b> m <b>" + dsec + "</b> s "; 
      
    		 setTimeout("countdown()",1000)
    		 return;
    	  }
    	  //else, if not yet
    	  else
    	  {
    		 var countdownDiv = document.getElementById("countdown");
    		 countdownDiv.innerHTML = "<font color=#990000><b>" + dday + "</b> days</font> <b> " + dhour + "</b> h <b>" + dmin + "</b> m <b>" + dsec + "</b> s "; 
    		 setTimeout("countdown()",1000)
    	  }
       }
    }
    if(document.getElementById)
    {
       document.write("");
       document.write("<div id=countdown></div>");
       document.write("<br>");
       countdown();
    }
    else
    {
       document.write("");
       document.write("");
       document.write("<br>");
    }
    </script>
    </head>
    <body onload="countdown();">
    <form action="tsncountdownscript.cfm" method="post">
     <input type="submit" name="Draft" value="Submit">
    </form>
    </body>
    </html>
    "Oh, you hate your job? Why didn't you say so? There's a support group for that.
    It's called EVERYBODY, and they meet at the bar."

    --Drew Carey


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
  •