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).
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.