Is there a way to get a Java script return value into a PHP variable.
I want to do something like this:
<?
echo "<SCRIPT language=JAVASCRIPT>";
echo "document.write(screen.width);"; // just for debug
echo "var sw =screen.width";
echo "</SCRIPT>";
echo $sw; // I know this is not working, but it is somehow what i want
?>
Java to PHP
Moderator: General Moderators
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Basically PHP is server side and Javascript is client side, this means that the PHP script has finished before the Javascript starts - they do not run at the same time. So it is relatively easy to pass a variable from PHP to Javascript as the sticky says. If you want to do it the other way around you need to send the variable to the server somehow, this means that you need to set it in a cookie, in the URL's query string or post it via a form and refresh the page. You will then be able to give the PHP script access to the variable. You cannot send a variable directly from Javascript to PHP.
Mac
Mac