JS is Client side , PHP is server side. So there is not a direct way to do the passing but you can do what you need to do by another method and AJAX is best option to it. Apart from this as an example, Following is the trick in which i am assiging screen width to my php varaible from javascript and I can echo its width by echo $width
but actually the javascript code is being executing on echo and variable $width doesnot hold the value of screensize i.e in my case 1366
its actually hold the javascript code (<script> document.write(window.screen.width); </script>)
thats being executed on echo .
$width = '<script> document.write(window.screen.width); </script>';
echo $width;