Hi, i'm still new to javascript but how would i make a javascript coundown timer to countdown from a time length stored in php variable <?=$pt?> (for example 3:30 in minutes and seconds) and to start counting from the click of a button. and displays it in the specified div/anchor/input/ or any other tag through the tag's id or name. So basiaclly a javascript timer that counts down from the time stored in <?=$pt?> on button click.
You can assign php variable to javascript like this var curr_time = <?=$pt?>; and then you can use javascript date function to manipulate it. http://www.quackit.com/javascript/javascript_date_and_time_functions.cfm
I knew this, but i need the code to countdown from the time stored in the variable in seconds and display each decrement.
I managed to write something close to what i wanted, but it's a count-up script rather than a count down. any way if you need it: <script type="text/javascript"> var c=0; var g=00; var t; var k=120; var ir; var d; var h=60; function timedCount() { document.getElementById('txt').value=d; c=c+1; ir=ir+1; if(c<=h) { if(c<10) {d = g+":0"+c;} else {d = g+":"+c;} } if(c>h) { g = g+1; c=0; } t=setTimeout("timedCount()",1000); } </script> </head> <form> <input type="text" id="txt"> <input type="button" onclick="timedCount()"> </form> Code (markup):