You can't pass arguments to the PHP code through JavaScript, only in one way, if you reload the page with some parameters.
Etc.
index.html------
<body onLoad="location.href=page2.php?var=1">
</body>
page2.php------
<body>
<?=var?> //output = 1
</body>
You have to remember that the PHP code execute when the server get a request of an page, and the JavaScript do execute at the client computer. So you have to reload/redirect before you can get something from the JavaScript to the PHP.
Regards,
Johan