SitePoint Sponsor

User Tag List

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

    Exclamation Error in javascript countdown code

    Hi! I've been staring at this code for a week now, trying to figure out my bug! It is drivign me up the wall!! The codeis for a javascript countdown of 3 minutes. It pulls the start time from a database using coldfusion. I can get it to display 3 minutes but can't get it to count down! Some new eyes and some help will be greatly appreciated


    Code:
    <cfquery name="GetStartDate" datasource="#ffldsn#">
    	Select PropValue
    	From ffl_prop
    	where propname='StartDraftTime' and Leagueid = #LeagueValue#
    </cfquery>
    
    <cfset DraftTickerTime = ParseDateTime("#GetStartDate.PropValue#")> 
    <cfset DraftTickerTime2 = DateAdd("n",3,"#DraftTickerTime#")>
    
    <cfoutput>
    var yr=#dateFormat(DraftTickerTime2,"yyyy")#;
    var mo=#dateFormat(DraftTickerTime2,"m")#;
    var da=#dateFormat(DraftTickerTime2,"d")#;
    var ho=#TimeFormat(DraftTickerTime2,"H")#;
    var mi=#TimeFormat(DraftTickerTime2,"m")#;
    var sec=#TimeFormat(DraftTickerTime2,"s")#; 
    
    var todaym = #dateFormat(DraftTickerTime,"m")#;
    var todayd = #dateFormat(DraftTickerTime,"d")#;
    var todayh = #dateFormat(DraftTickerTime,"d")#;
    var todaymin = #TimeFormat(DraftTickerTime,"m")#;
    var todaysec = #TimeFormat(DraftTickerTime,"s")#; 
    var todayy = #Dateformat(Drafttickertime,"yyyy")#;
    </cfoutput> 
    function countdown()
    {
       var today = new Date();
      
    
       if(todayy < 1000)
       {
          todayy += 1900;
       }
    
      
       var todaystring = todaym+"/"+todayd+"/"+todayy+" "+todayh+":"+todaymin+":"+todaysec;
    
       futurestring = (mo-1+1)+"/"+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(dsec <= 0 && dmin <= 0 && dday <= 0)
          {
             //When countdown ends!!
    		 
              var countdownDiv = document.getElementById("countdown");
             countdownDiv.innerHTML = "<b><div class='small'><font color='red'>Times Up!<BR>Please Draft</font></div></b><br>" + futurestring + "<br>" + todaystring; 
    
          
          }
    	  else if(dmin > 6)
          {
             //When countdown ends!!
    		 
              var countdownDiv = document.getElementById("countdown");
             countdownDiv.innerHTML = "<b><div class='small'><font color='red'>Times Up!<BR>Please Draft</font></div></b><br>" + futurestring + todaystring ; 
    
          
          }
          //if on day of occasion
          else if(todayy == yr && todaym == mo && todayd == da)
          {
             // need to handle this!!
    		 
              var countdownDiv = document.getElementById("countdown");
             countdownDiv.innerHTML = "<b>" + dmin + "</b> m <b>" + dsec + "</b> s hee"; 
    
             setTimeout("countdown()",1000)
          }
          //else, if not yet
          else
          {
             var countdownDiv = document.getElementById("countdown");
             countdownDiv.innerHTML = "<b>nothing</b>"; 
          }
       }
    }
    
    if(document.getElementById)
    {
       document.write("<div id=countdown></div>");
       document.write("<br>");
    
       countdown();
    }
    else
    {
        document.write("<br>");
       document.write("<div></div>");
       document.write("<br>");
    }

  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'm not surprised you have been looking at that for a week. Maybe cleaning it up so it's easy to read, would help. But if you explain what your trying todo may i can come up with something.

    PHP Code:
    var timer = [cold fusion];

    iTimerID window.setTimeout("do_code",timer); 

  3. #3
    SitePoint Addict
    Join Date
    Jan 2002
    Location
    Omaha, NE
    Posts
    281
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What I am trying to do is have a javascript countdown from 3 minutes to zero, at zero it displays a message saying your time is up. I can get it to show the start of the 3 minutes, but I can't get it to countdown.

  4. #4
    SitePoint Zealot
    Join Date
    Jul 2002
    Posts
    168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't know enough java to be able to point out what exactly is wrong with your script, but why do you need so much code for a simple counter?

    Instead of trying make the above work, why don't you just enter "javascript timer" into Google, look at some examples and adapt to your needs?


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
  •