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
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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.