Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

PHP and JavaScript

How can I get PHP and JavaScript to communicate? by rhowes
Posted: 29 Oct 01

This is a common question and one I had to resolve myself recently. The important thing to remember is PHP is server side and JavaScript is client side.

But usually this is all anyone says when you ask. What they don't tell you is what IS possible.

Generally if you want to pass "instructions" or variables (e.g. flags) from JavaScript to PHP, then do the following:

1. Write your JavaScript to perform some action, e.g. when you click a button.
2. Write the "result" to a hidden form text field.
3. Reload the page and "read" the hidden text field value in PHP.

The reverse is also true . During PHP processing, if you want to pass on some "message" to JavaScript then set a hidden form field using PHP. On the client side you can "read" the message when the user performs some Javascript triggering action, or you can "read" it immediately the page loads with the JavaScript OnLoad event.

Again, because of the nature of the two technologies (server and client side) you can only communicate petween them by "reloading" a page (usually by redirecting to itself).

Hope this helps.

Back to PHP FAQ Index
Back to PHP Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close