Posted by Andy Hassall on 06/29/05 02:04
On 28 Jun 2005 15:47:34 -0700, mbasil7@gmail.com (mbasil7) wrote:
>I want to use a javascript variable in php.
This is more complicated than it may appear.
>The reason is that i want
>to know the client's screen resolution.
>Here is the code i'm using:
>
><head>
><script language='JavaScript'>
> <!--
> var a=(screen.width-750)/2;
>
> function getvariable(val) {
> var dummy = eval(val);
> document.write(dummy);
> }
> // -->
> </script>
> <?php
> function get_JS_var($js_var_name) {
> $x = "<script> getvariable('" . $js_var_name . "'); </script>";
> return $x;
What are you expecting this to do?
> }
>?>
></head>
><body>
><?php
>$screen_pos = get_JS_var("a");
>$b="left:".$screen_pos."";
>?>
><div style="position:absolute; <?print $b;?>; top:0; z-index:4">
This isn't using a Javascript variable in PHP, this is outputting invalid CSS
within HTML (trying to put a <script> tag in a style).
You seem to be badly confused as to the execution order and execution location
of PHP versus Javascript.
In this case it appears you're better off leaving PHP out of the picture and
just doing this all in client-side Javascript?
--
Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Navigation:
[Reply to this message]
|