Jump to content

Executing some php code


RockinPurdy

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/78171-executing-some-php-code/
Share on other sites

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.

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.

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.