Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Darrel Lyons
2,991 PointsNon-refresh timer
How can i make a countdown that will countdown without refreshing a div or a page. I have a function that makes thee time from the database but i want it to countdown on the page itself without refreshing any page. Here is the function :
function maketime($last){
$timenow = time();
if($last>$timenow){
$order = $last-$timenow;
while($order >= 60){
$order = $order-60;
$ordermleft++;
}
while($ordermleft >= 60){
$ordermleft = $ordermleft-60;
$orderhleft++;
}
if($ordermleft == 0){
$ordermleft = "";
} else {
$ordermleft = "$ordermleft Minutes";
}
if($orderhleft == 0){
$orderhleft = "";
} else {
$orderhleft = "$orderhleft Hours";
}
return "$orderhleft $ordermleft $order Seconds";
}}
3 Answers

Dustin Matlock
33,856 PointsAre you just wanting to learn how or needing one of these? You might want to check out FlipClock.js otherwise the code below is a basic example.
var newYear = new Date();
newYear = new Date(newYear.getFullYear() + 1, 1 - 1, 1);
$('#defaultCountdown').countdown({
until: newYear
});
$('#removeCountdown').click(function () {
var destroy = $(this).text() === 'Remove';
$(this).text(destroy ? 'Re-attach' : 'Remove');
$('#defaultCountdown').countdown(destroy ? 'destroy' : {
until: newYear
});
});

Darrel Lyons
2,991 PointsNo , i have a timer set in the database for40 or sometimes 60seconds with time() + 40-60. I just need it to countdown without refreshing the page.