PHP (scripts) are run on the server. When it finally gets to your client (user) the PHP is gone from the page. What's left is the results of the php being run on the server. Thus, you CAN NOT set a php data value on the client since there is no mechanism on the client to do anything with it. Or PHP function, etc. PHP is also your gateway into SQL, MySQL, etc. - they reside on the server side.
JAVASCRIPT is run on the client (optionally - it can be disabled!). Simply put, it gives your page, as rendered on the client, functionality. In particular, it's useful for handling events (such as content of a drop-list being changed). It can also be involved in your page setup and operation - such as a refresh timer or data validation.
So, the PHP never gets to the client and the client doesn't understand PHP. Quite the dilemma for you and your problem.
There are two common ways to get your data from the client to the server.
1)
Use web forms[
^]. They can call scripts, and ultimately
target a server-side page that can be sent the data in your form. Note that your page will be refreshed.
2)
Use AJAX[
^]. This is a javaScript that has functionality that sends information to the server - to a PHP file, which can then handle it and do what you wish with it. It does not refresh the current page - but better yet - it can update content on the current page without the refresh.
Sending data between the two takes some getting used to.