Countdown timer.. should be easy!

Discussion in 'JavaScript' started by love_bug, Jul 31, 2008.

  1. #1
    Hi im not good with javascripts.. so can someone show me how to show countdown timer (10 to 0) on a submit button, i mean when click on it.. not on pageload..thanks
     
    love_bug, Jul 31, 2008 IP
  2. yleiko

    yleiko Peon

    Messages:
    74
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    
    <script language="javascript">
    function countdown(i)
    {
    	i--;
    	if(i > 0) {
    		document.getElementById("myButton").value = "last "+i+"seconds"
    		setTimeout("countdown("+i+")", 1000);
    	} else {
    		document.getElementById("myButton").value = "Do it again"
    	}
    }
    </script>
    <input type="button" id="myButton" value="Click Me" onclick="countdown(10)" />
    
    
    Code (markup):
     
    yleiko, Aug 1, 2008 IP