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)

    Error in javascript timer / countdown

    I've been playing around with this script, and i got this timer to start at 3 min but I can't get it to count down! Any suggestions? I've been racking my brain on this for awhile....hopefully some new eyes will help!

    Thanks


    <cfquery name="GetStartDate" datasource="#ffldsn#">
    Select PropValue
    From ffl_prop
    where propname='StartDraftTime' and Leagueid = #LeagueValue#
    </cfquery>

    <cfset DraftTickerTime = ParseDateTime("#GetStartDate.PropValue#")>

    <cfset DraftTickerTime = DateAdd("n",-2,"#DraftTickerTime#")>
    <cfset DraftTickerTime = DateAdd("s",15,"#DraftTickerTime#")>
    <cfoutput>
    var yr=#dateFormat(DraftTickerTime,"yyyy")#;
    var mo=#dateFormat(DraftTickerTime,"m")#;
    var da=#dateFormat(DraftTickerTime,"d")#;
    var ho=#TimeFormat(DraftTickerTime,"H")#;
    var mi=#TimeFormat(DraftTickerTime,"m")#;
    var sec=#TimeFormat(DraftTickerTime,"s")#;
    </cfoutput>
    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+":"+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>";


    }
    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>";


    }
    //if on day of occasion
    else if(todayy == yr && todaym == (mo-1) && todayd == da)
    {
    // need to handle this!!

    var countdownDiv = document.getElementById("countdown");
    countdownDiv.innerHTML = "<b>" + dmin + "</b> m <b>" + dsec + "</b> s";

    setTimeout("countdown()",1000)
    }
    //else, if not yet
    else
    {

    }
    }
    }

    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
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't mean to sound rude, but I think you would get more people to help you debug your code if you put it in the vbCode 'CODE' tags (the # button on the toolbar) That way all the tabulation is preserved, and word-wrap is disabled. Because I can't scan the code and see it's logical structure in this format. Please re-post it and I'll be certain to help you
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




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

    Preserved Code

    Sorry for the rookie like mistake, i wasn't having any problem with tabulation or word wrap and didn't think that someone else would...my bad! Hope this helps!!! Thanks



    Code:
    <cfquery name="GetStartDate" datasource="#ffldsn#">
    Select PropValue
    From ffl_prop
    where propname='StartDraftTime' and Leagueid = #LeagueValue#
    </cfquery>
    
    <cfset DraftTickerTime = ParseDateTime("#GetStartDate.PropValue#")> 
    
    <cfset DraftTickerTime = DateAdd("n",-2,"#DraftTickerTime#")> 
    <cfset DraftTickerTime = DateAdd("s",15,"#DraftTickerTime#")>
    <cfoutput>
    var yr=#dateFormat(DraftTickerTime,"yyyy")#;
    var mo=#dateFormat(DraftTickerTime,"m")#;
    var da=#dateFormat(DraftTickerTime,"d")#;
    var ho=#TimeFormat(DraftTickerTime,"H")#;
    var mi=#TimeFormat(DraftTickerTime,"m")#;
    var sec=#TimeFormat(DraftTickerTime,"s")#;
    </cfoutput> 
    
    //The above code works...it translate a value in a
    //database  to  the date using coldfusion, then adds 3 
    //min for the futrue time
    
    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+":"+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>"; 
    
    
    }
    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>"; 
    
    
    }
    //if on day of occasion
    else if(todayy == yr && todaym == (mo-1) && todayd == da)
    {
    // need to handle this!!
    
    var countdownDiv = document.getElementById("countdown");
    countdownDiv.innerHTML = "<b>" + dmin + "</b> m <b>" + dsec + "</b> s"; 
    
    setTimeout("countdown()",1000)
    }
    //else, if not yet
    else
    {
    
    }
    }
    }
    
    if(document.getElementById)
    {
    document.write("<div id=countdown></div>");
    document.write("<br>");
    
    countdown();
    }
    else
    {
    document.write("<br>");
    document.write("<div></div>");
    document.write("<br>");
    }

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

    Any ideas?

    Anyone have any ideas?


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
  •