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 2 of 2

Thread: ajax problem

  1. #1
    New to the CF scene
    Join Date
    May 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    ajax problem

    hello

    i set time in item to show in my website assume 06-05-2011 at midnight date increase 1 day and then at morning or 12 hour date decrease 1 day

    what can i do if i don't want date increase or decrease between 12 hour..but when it arrive to 06-05-2011 on calender so the time must count down

    this is java code

    function calc_counter_from_time22(diff)
    {

    if (diff > 0) {
    hours=Math.floor(diff / 3600)
    minutes=Math.floor((diff / 3600 - hours) * 60)
    seconds=Math.floor((((diff / 3600 - hours) * 60) - minutes) * 60)
    } else {
    hours = 0;
    minutes = 0;
    seconds = 0;
    }

    if(diff < 86400){
    return twodigit(hours) + ":" + twodigit(minutes) + ":" + twodigit(seconds);
    }
    else{


    var Tday = Math.round(diff / (60 * 60 * 24));

    var addDay = Tday;
    var d = new Date();
    d.setDate(d.getDate()+addDay);
    mkMonth=d.getMonth()+1;
    mkMonth=new String(mkMonth);
    if(mkMonth.length==1){
    mkMonth="0"+mkMonth;
    }
    mkDay=d.getDate();
    mkDay=new String(mkDay);
    if(mkDay.length==1){
    mkDay="0"+mkDay;
    }
    mkYear=d.getFullYear();
    return mkDay+"-"+mkMonth+"-"+mkYear;
    }

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    3,760
    Thanks
    23
    Thanked 546 Times in 545 Posts
    The way I understand you = You want to show the time on your web site and have a count down to a date set by you. If this is right I have it below. It's not Ajax just javascript by it works automatically.

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html>
    <head>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    <script type="text/javascript">
    function updateTime() {
    		now      = new Date();
    		document.getElementById("time").innerHTML = now;
    	kickoff  = Date.parse("may 8, 2011 21:05:00");
    	diff = kickoff - now;
    if (diff > 0){
    	days  = Math.floor( diff / (1000*60*60*24) );
    	hours = Math.floor( diff / (1000*60*60) );
    	mins  = Math.floor( diff / (1000*60) );
    	secs  = Math.floor( diff / 1000 );
    
    	dd = days;
    	hh = hours - days  * 24;
    	mm = mins  - hours * 60;
    	ss = secs  - mins  * 60;
    
    	document.getElementById("countdown_time").innerHTML = dd + ' days ' + hh + ' hours ' + mm + ' minutes ' + ss + ' seconds' ;
    	}else{
    		document.getElementById("countdown_time").innerHTML = 'It is Over! Go Home.';
    		die;
    	}   // YOU CAN PRINT it's over HERE!!!!!!!!!!!!!!!!!!!!!!!!!!!AND DIE!!!!!!!!!!!
    }
    setInterval('updateTime()', 1000 );
    
    </script>
    <title>Countdown Timer</title>
    </head>
    <body>
    <div id="time"></div>
    <div id="countdown_time"></div>
    </body>
    </html>


  •  

    Posting Permissions

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