onClick echo out php variable

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Smudly
Forum Commoner
Posts: 71
Joined: Wed Jun 09, 2010 10:09 pm

onClick echo out php variable

Post by Smudly »

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?
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: onClick echo out php variable

Post by Jonah Bron »

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.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: onClick echo out php variable

Post by califdon »

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