I have a form, that when the user click Submit, I need a php variable to be echoed to the page.
This is for an upload page. So when they are waiting for the file to upload, it will say "Uploading..." until the upload is complete.
All I know so far is I need to create a javascript function and include it in the submit button. This is all I have so far in the submit button tag:
onClick="Transferring();"
Now I need to figure out the code to include in this function.
Any ideas?
onClick echo out php variable
Moderator: General Moderators
- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
Re: onClick echo out php variable
Where do you want the "Uploading..." message to be? On the form target page? If that's the case, you can't make in disappear after the upload is finished. You'll need to redirect after it's finished.
Re: onClick echo out php variable
Jonah Bron is right, of course, but just to clarify the environment for you, you're not talking about a PHP variable at all. The PHP was all finished and the variables disappeared before the page was ever sent to the browser! When you want to do something based on any user action after the page is seen by the user, it must be done in Javascript, a client-side language. So your Transfering() function could update an existing HTML element like a <div> or a <span>, to set its InnerHtml property to "Uploading...", but as Jonah said, Javascript has no way to know when the upload is complete, unless you use AJAX, which is another technique altogether. But your server-side PHP script could redirect to a new page (which could say "Completed" or something) when it has received the file, as Jonah said.