Jump to content


Photo

JavaScript to PHP


  • Please log in to reply
2 replies to this topic

#1 ldsmike88

ldsmike88
  • Members
  • PipPipPip
  • Advanced Member
  • 168 posts
  • LocationFlorida

Posted 08 April 2006 - 04:31 AM

I am getting a monitors resolution with JavaScript. After I get the resolution I want to make it a PHP variable. I want to do all of this on one page. How do I do it? JavaScript:

<script type="text/javascript"> document.write(screen.width+"x"+screen.height); </script>

If I am going to echo the variable it works like this:

$resolution = '<script type="text/javascript"> document.write(screen.width+"x"+screen.height); </script>';

The only problem is I am not going to echo it, I am going to put it in mySQL database. Does anyone know how to pass this variable to php? Thanks!

Mike

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 08 April 2006 - 04:45 AM

Remember, PHP runs on the server and Javascript runs on the client. PHP is done with all of its processing before Javascript starts to execute. The only way to do what you want is to use AJAX where your Javascript script starts up a small PHP script in the background and passes the information.

Ken

#3 ldsmike88

ldsmike88
  • Members
  • PipPipPip
  • Advanced Member
  • 168 posts
  • LocationFlorida

Posted 08 April 2006 - 04:53 AM

Hmm... Maybe I'll look into passing it through a cookie. I have been meaning to look that up for a while. Thanks!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users