Back to the top
Reference:
The referenced manual page above gives a pretty straightforward explanation of the issue: The server doesn't know what the client is doing. If you want something to happen on the server (i.e., run any sort of PHP script) you need the client to make a request. If you want PHP to know about any sort of Javascript variable, then the client will have to send that variable's value back as part of the request.
Now, personally, I'm not a big fan of the self-refereshing idea given in the manual. But that's because there's a much sexier method available, now called Ajax. There are many crotchety old people around who were doing this long before it was called "Ajax" and they'd be happy to remind you of that fact if you let them. Back then it was a lot more unreliable and incompatible support between browsers and rotten Javascript implementations and we had to walk fifteen miles in the snow and it was uphill both ways ... where was I?
Ajax is a catchall term for what might more technically be called XMLHttpRequest or XHR (even though XML isn't necessarily involved: JSON (for which PHP has inbuilt support) is often better suited to the task. But "X" is a sexier letter than "J".) It allows a Javascript program to request something from the server, get a response, and act on that response, without the user having to leave or refresh the page.
There are screeds of Ajax libraries floating around of varying complexity and comprehensiveness. But whether you go with prototype (which does a lot more than just Ajax) or jQuery or JPSpan or cpaint or whathaveyou, the fact is they all boil down to not that much more than what Rasmus runs through in his tutorial.