RockinPurdy Posted November 21, 2007 Share Posted November 21, 2007 Hey, this is more of a javascript question, but incorporates php. I have a javascript script that creates a countdown and displays it in a text field in a form. What I want to do is, after the countdown finishes, execute some php code but have no clue how i would go about doing this. What are my options? Heres the script: <script> var xxx = 30 var yyy = 1 function startClock3(){ if(xxx!=="Done"){ xxx = xxx-yyy document.frm.clock.value = xxx setTimeout("startClock()3", 1000) } if(xxx==0){ x="Done"; document.frm.clock.value = xxx } } </script> Quote Link to comment Share on other sites More sharing options...
btherl Posted November 21, 2007 Share Posted November 21, 2007 You'll need to use ajax .. basically, you can have javascript call another php script to execute the code. You can find quite a few tutorials in google. Edit: Or if you don't mind losing the current page, you can redirect the page with javascript. That's simpler. Quote Link to comment Share on other sites More sharing options...
BenInBlack Posted November 21, 2007 Share Posted November 21, 2007 well, you have to remember when your running Javascript that means that you have already left the server which is where PHP is running and you are in the browser, so you can't redirect or run php code. You can do 1. run the window.location = 'http://yourdomain.com/yourphpfile.php' and this will cause the browser to request new code to run from the server 2. like btherl said: Make an AJAX Call which process the yourphpfile.php and returns the results. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.