Page 1 of 1

simple echo

Posted: Sun Aug 01, 2010 4:24 pm
by JonathanStanton
Why doesn't this code work?

<script type="text/javascript">
width = screen.width;
alert('<?php echo $_GET['width']; ?>');
</script>

Re: simple echo

Posted: Sun Aug 01, 2010 4:26 pm
by superdezign
That depends. What are you trying to do? What are you expecting this code to accomplish?

Re: simple echo

Posted: Sun Aug 01, 2010 4:32 pm
by JonathanStanton
the Javascript variable is a JSON request so in actuality it's

width = data.lastID;
alert(width);
alert('<?php echo $_GET['width']; ?>');

the first Alert returns my variable correctly
but I really need it do be echo through PHP because I'm putting it through some jQuery stuff and it wont work with js variables needs to be echo'ed

Re: simple echo

Posted: Sun Aug 01, 2010 4:49 pm
by superdezign
Again, not exactly sure what you are trying to accomplish...

However, it seems as if you are trying to access data that PHP does not have, or trying to send data to PHP. If you do not have "width" defined in the query string of your URL, then $_GET['width'] will be empty. If you are trying to send this width to PHP, then you are out of luck. PHP is server-side, and thus is processed well before JavaScript (which is client-side) is. The only way for JavaScript to communicate with PHP is through AJAX, and it's not exactly a simple process.

Re: simple echo

Posted: Sun Aug 01, 2010 5:40 pm
by JonathanStanton
oh I understand now, thank you :)