Java to PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pbangsoe
Forum Newbie
Posts: 4
Joined: Wed Oct 02, 2002 5:55 am
Location: Copenhagen, Denmark

Java to PHP

Post by pbangsoe »

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
?>
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Please read this:
viewtopic.php?t=1030

Mac
pbangsoe
Forum Newbie
Posts: 4
Joined: Wed Oct 02, 2002 5:55 am
Location: Copenhagen, Denmark

Post by pbangsoe »

:?: May be i am not that hard core, but i want to get a value FROM Java not the other way around.

Or am i missing something !
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

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
Post Reply