Basic concepts:
JAVASCRIPT is executed by the client, the Web browser.
PHP is executed by the Web server before anything is sent to the client.
If something happens in Javascript and you want PHP to do something with it, you have to submit a GET or POST request for a new page, passing the value appropriately.