r1x7 Posted April 4, 2007 Share Posted April 4, 2007 I'm new to php and i wanted to know how to make a count down timer in seconds. Iv tryed a for loop and using sleep(1) and looping it 5 times but it holds the hole page from loading until the loop has finished. What i want to do is load the hole page then sleep for 5 seconds then display a string. Link to comment https://forums.phpfreaks.com/topic/45564-php-count-down-timer/ Share on other sites More sharing options...
monk.e.boy Posted April 4, 2007 Share Posted April 4, 2007 You need to do this on the CLIENT, PHP runs on the server. Javascript runs on the clients. monk.e.boy Link to comment https://forums.phpfreaks.com/topic/45564-php-count-down-timer/#findComment-221272 Share on other sites More sharing options...
r1x7 Posted April 4, 2007 Author Share Posted April 4, 2007 Ok i found some code but it will not start when i try to start a php function inside the javascript. If i remove the function from the javascript it runs ? "NOTE :: I need to print data from a php function not just write it the JS way" <body> <?php function Sendstring() { return "Some test"; } ?> <form name="redirect"> <center> <font face="Arial"><b>Count Down<br><br> <form> <input type="text" size="3" name="redirect2"> </form> <script> var countdownfrom=5 var currentsecond=document.redirect.redirect2.value=countdownfrom+1 function countredirect(){ if (currentsecond!=1){ currentsecond-=1 document.redirect.redirect2.value=currentsecond } else{ <?php print Sendstring(); // 5 seconds has passed ?> return } setTimeout("countredirect()",1000) } countredirect() </script> </body> </html> Link to comment https://forums.phpfreaks.com/topic/45564-php-count-down-timer/#findComment-221284 Share on other sites More sharing options...
monk.e.boy Posted April 5, 2007 Share Posted April 5, 2007 Oh. My. God. You do understand that PHP runs on the SERVER? Please take a moment and really think about this. If I download you web page, your PHP does NOT NOT NOT run on my machine. Now browse to your page and do a 'view source' and take a look at your javascript, it should look like this: if (currentsecond!=1){ currentsecond-=1 document.redirect.redirect2.value=currentsecond } else{ Some test return I hope you can see that this is invalid Javascript and will not run. monk.e.boy Link to comment https://forums.phpfreaks.com/topic/45564-php-count-down-timer/#findComment-221916 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.