Jed Verity wrote:

>I can't find any information on passing JavaScript variables to PHP on the
>same page (i.e. not through the POST information of a submitted form). Is
>this because it's not possible?
>
Basically, this is not possible.

A common area of confusion to those new to Web programming is the 
distinction between client-side and server-side code. PHP is an example 
of a server-side scripting language, while JavaScript is client-side. To 
PHP, anything that is not PHP is simply output. It doesn't matter if the 
output is HTML, JavaScript, XML, an image, etc. - it's all "not PHP."

When a user requests a PHP script, the PHP part of the script is 
executed prior to the output being sent to the client. Remember, the 
output may contain JavaScript. Once the output reaches the browser, the 
browser will attempt to render the HTML, execute the JavaScript, and 
whatever else is appropriate. So, to get back to your question, you are 
wanting to know how to have the browser (which is executing the 
JavaScript) be able to send a JavaScript variable to PHP (which could be 
thousands of miles away on whatever Web server the page was obtained 
from) "on the same page," which means you want to be able to do this 
without communicating back to the Web server.

So, your question can be summarized into:

"How can my browser send data back to the Web server without any further 
communication with the Web server?"

Hopefully that explains how it is impossible.

The terms server-side and client-side are ignored by most people, 
understandably, because this industry is littered with useless terms 
that do little to describe what is really happening (in the case of "Web 
services," the term is actually misleading in my opinion). However, 
these terms are very descriptive, and once you can begin to understand 
which code is executed on the server-side (by the Web server prior to 
sending the response to the Web client) and which code is executed on 
the client-side (by the Web client after receiving the response from the 
Web server), all of these types of questions will make more sense to you.

Hope that gives a good description of the difference and can help you 
solve whatever problem you're currently working on.

Chris


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to