You are here: Re: use a javascript variable in php? « PHP Programming Language « IT news, forums, messages
Re: use a javascript variable in php?

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация