Yep. Stuff it in a form from JS to PHP, then for PHP-to-JS you'll either have to place the var in a form (hidden maybe - then JS can access as needed) or echo a JS var assignment.
eg:
PHP Code:
<?php
$foo = 'myid';
echo '<script> var js_id = "{$foo}";</script>';
?>
-r