Simple countdown timer using javascript

we can create an simple countdown timer using javascript without any javascript library

for that first we need to create an html element with the following

<div id="timer">2:00</div>

And add the javacript code from below

<script type="text/javascript">
var timeoutHandle;
function countdown(minutes) {
    var seconds = 60;
    var mins = minutes
    function tick() {
        var counter = document.getElementById("timer");
        var current_minutes = mins-1
        seconds--;
        counter.innerHTML =
        current_minutes.toString() + ":" + (seconds < 10 ? "0" : "") + String(seconds);
        if( seconds > 0 ) {
            timeoutHandle=setTimeout(tick, 1000);
        } else {

            if(mins > 1){

               // countdown(mins-1);   never reach “00″ issue solved:Contributed by Victor Streithorst
               setTimeout(function () { countdown(mins - 1); }, 1000);

            }
        }
    }
    tick();
}

countdown(2);

</script>

countdown(2) is the function which invokes the timer and the minutes as the only parameter

and we are done!

The working example is shown below

2:00

Hope this helps to create simple countdown timer using javascript without any javascript library

As per the request from Steve i am adding the timer functionality in the format H:M:S

<div id="hms">00:10:10</div>

And add the javacript code from below

<script type="text/javascript">
    var timeoutHandle;
    function count() {

    var startTime = document.getElementById('hms').innerHTML;
    var pieces = startTime.split(":");
    var time = new Date();    time.setHours(pieces[0]);
    time.setMinutes(pieces[1]);
    time.setSeconds(pieces[2]);
    var timedif = new Date(time.valueOf() - 1000);
    var newtime = timedif.toTimeString().split(" ")[0];
    document.getElementById('hms').innerHTML=newtime;
    timeoutHandle=setTimeout(count, 1000);
}
count();

</script>

The working example is shown below

00:10:10

For the timer to continue on page refresh, you can use this code to store the time in cache and reuse that to start the timer

var timeoutHandle;
function countdown(minutes,stat) {
    var seconds = 60;
    var mins = minutes;
	 
	if(getCookie("minutes")&&getCookie("seconds")&&stat)
	{
		 var seconds = getCookie("seconds");
    	 var mins = getCookie("minutes");
	}
	 
    function tick() {
		
        var counter = document.getElementById("timer");
		setCookie("minutes",mins,10)
		setCookie("seconds",seconds,10)
        var current_minutes = mins-1
        seconds--;
        counter.innerHTML = 
		current_minutes.toString() + ":" + (seconds < 10 ? "0" : "") + String(seconds);
		//save the time in cookie
		
		
		
        if( seconds > 0 ) {
            timeoutHandle=setTimeout(tick, 1000);
        } else {
             
            if(mins > 1){
                 
               // countdown(mins-1);   never reach “00″ issue solved:Contributed by Victor Streithorst    
               setTimeout(function () { countdown(parseInt(mins)-1,false); }, 1000);
                     
            }
        }
    }
    tick();
}
function setCookie(cname,cvalue,exdays) {
    var d = new Date();
    d.setTime(d.getTime() + (exdays*24*60*60*1000));
    var expires = "expires=" + d.toGMTString();
    document.cookie = cname+"="+cvalue+"; "+expires;
}
 function getCookie(cname) {
    var name = cname + "=";
    var ca = document.cookie.split(';');
    for(var i=0; i<ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1);
        if (c.indexOf(name) == 0) {
            return c.substring(name.length, c.length);
        }
    }
    return "";
}
countdown(2,true);

Get country list in magento

By accessing the magento collections we can get country list in magento,
Here is the code to get all the countries in magento

<?php

   $collection = Mage::getModel('directory/country')->getCollection();    
   foreach ($collection as $country) 
   {
       $cid = $country->getId();
       $cname = $country->getName();
       echo 'Country ID -> '.$cid.' Country Name -> '.$cname.'<br/>';
                              
   }
?>

Hope you get country list in magento using this code snippet.

Show order summary inside magento success page

Sometimes we need to show order summary inside magento success page
Copy this snippet of code inside template/checkout/success.phtml

<?php
    $_customerId = Mage::getSingleton('customer/session')->getCustomerId();
    $lastOrderId = Mage::getSingleton('checkout/session')->getLastOrderId();
    $order = Mage::getSingleton('sales/order'); 
    $order->load($lastOrderId);
    $_totalData =$order->getData(); 
    $_sub = $_totalData['subtotal'];
    //get order details
    //print_r($_totalData);
    $_order   = $this->getOrder();
    $allitems = $order->getAllItems();
    foreach($allitems as $item)
    {
    //get items in cart
    // print_r($item)
    }
?>

Hope you will get how to show order summary inside magento success page