Jump to content

php count down timer


r1x7

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.