Why doesn't this code work?
<script type="text/javascript">
width = screen.width;
alert('<?php echo $_GET['width']; ?>');
</script>
simple echo
Moderator: General Moderators
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
Re: simple echo
That depends. What are you trying to do? What are you expecting this code to accomplish?
-
JonathanStanton
- Forum Newbie
- Posts: 10
- Joined: Wed Jul 21, 2010 10:07 am
Re: simple echo
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
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
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
Re: simple echo
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.
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.
-
JonathanStanton
- Forum Newbie
- Posts: 10
- Joined: Wed Jul 21, 2010 10:07 am
Re: simple echo
oh I understand now, thank you 