PHP runs on the server, and generates a response which is sent back to the client. Javascript runs on the client, long after the PHP code has finished.
To send values from the client back to the server, you either need to submit a
<form>
, reload the page with the values in the querystring, or make an AJAX request.
Ajax - Developer guides | MDN[
^]