depending on your specific problem, that may be impossible. It's important to realize that PHP is processed before the page is transmitted to the client, where Javascript etc. then takes place. If you want to have a JS variable available for PHP, you will have to do a reload of the php code and pass the variable by either the URL (query string / get) or else as a (hidden) field in a form, submitted by post / get.