Passing Javascript variables to PHP

JavaScript and client side scripting.

Moderator: General Moderators

Locked
lvzrdoz
Forum Newbie
Posts: 7
Joined: Sun Feb 09, 2003 12:38 am
Location: Las Vegas

Passing Javascript variables to PHP

Post by lvzrdoz »

Maybe I'm staring at this too long. I'm trying to pass the screen width, obtained from Javascript screen.width, into a PHP variable. The results don't make any sense: (1) $REZ echos correctly but (2) $wyde never gets changed based on the value of $REZ. I'm running this from an 800x600 screen. For other sizes, change 800 to 1024 etc.

Somebody clue me in on what's going on here.

Bob from Las Vegas

<HTML><HEAD>
<?php $REZ = "<script language=javascript>
document.write(screen.width); </script>" ; ?>
</HEAD><BODY>
<?php
$wyde = "UNCHANGED!" ;

if( $REZ == 800 ) $wyde = "changed to Numeric 800";
if( $REZ == "800" ) $wyde = "changed to Alpha 800";

echo "REZ=" . $REZ . "! and variable is " . $wyde;;
?>
</BODY></HTML>
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Skyzyx
Forum Commoner
Posts: 42
Joined: Fri Feb 14, 2003 1:53 am
Location: San Jose, CA

Post by Skyzyx »

Well, I'm a PHP newbie, but a JS pro... how does this work...

Code: Select all

<HTML>
<HEAD>
<script language="JavaScript" type="text/javascript">
<?php
$REZ = ?>
screen.width;
<? ; ?>
</script>
</HEAD>
<BODY>
<?php
$wyde = "UNCHANGED!" ;

if( $REZ == 800 ) $wyde = "changed to Numeric 800";
if( $REZ == "800" ) $wyde = "changed to Alpha 800";

echo "REZ=" . $REZ . "! and variable is " . $wyde;;
?>
</BODY>
</HTML>
A note - screen.width returns an integer value, not a string.

Hope this helps.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Please don't cross-post, it just gets confusing trying to follow a thread.

If you would like to help please go here:
viewtopic.php?t=6475

Mac
Locked