Page 1 of 1

Passing Javascript variables to PHP

Posted: Thu Feb 13, 2003 10:07 pm
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>

Posted: Fri Feb 14, 2003 1:23 am
by volka

Posted: Fri Feb 14, 2003 2:02 am
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.

Posted: Fri Feb 14, 2003 2:06 am
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